我创建了一个 asp.net 4.0 Web 应用程序,它具有用于上传图像的 Web 服务。我通过将 Base64 字符串形式的图像从我的移动应用程序发送到 Web 服务来上传图像。
以下是我的代码:
public string Authenticate(string username, string password, string fileID, string imageData)
{
Dictionary<string, string> responseDictionary = new Dictionary<string, string>();
bool isAuthenticated = true; // Set this value based on the authentication logic
try
{
if (isAuthenticated)
{
UploadImage(imageData);
string result = "success";
var message = "Login successful";
responseDictionary["status"] = result;
responseDictionary["message"] = message;
}
}
catch (Exception ex)
{
responseDictionary["status"] = ex.Message;
responseDictionary["message"] = ex.StackTrace;
}
return new JavaScriptSerializer().Serialize(responseDictionary);
}
private void UploadImage(string uploadedImage)
{
// Convert Base64 String to byte[]
byte[] imageBytes = Convert.FromBase64String(uploadedImage);
MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length);
System.Drawing.Bitmap bitmap = (System.Drawing.Bitmap)Image.FromStream(ms);
string uploadPath = Server.MapPath("..\\uploads\\") + DateTime.Now.Ticks.ToString() + ".jpeg";
ms.Close();
bitmap.Save(uploadPath, System.Drawing.Imaging.ImageFormat.Jpeg);
bitmap.Dispose();
}
这段代码在我的本地 ASP.NET 开发服务器上运行良好,我能够在我的“上传”目录中看到上传的图像。但是,将代码传输到 FTP 目录后,我现在收到以下错误:
A generic error occurred in GDI+
我通过创建一个虚拟的 .aspx 页面并在 page_load 上创建一个文本文件来检查上传目录是否具有适当的权限,并且它工作正常。
即使在进行谷歌搜索之后,我也无法解决这个问题。有人可以帮我解决这个问题吗?
提前非常感谢。