我的网站在我的本地网络上运行,允许用户上传 zip 文件。但是当我开始在我的局域网(而不是本地主机)上测试它时,文件显示为 blob?例如:在运行 IIS express 的本地主机上,我可以上传 example.zip,它会像 example.zip 一样显示在上传文件夹中。现在,如果我尝试从另一台机器上传它,example.zip 会显示为 blob。有趣的是,如果我将文件重命名为 example.zip,并给出正确的扩展名,则文件完全完好,我可以阅读它。我认为这可能是文件夹权限,所以我让每个人都可以完全控制上传文件夹以进行测试,但它仍然无法正常工作。这是来自我的 API 控制器的代码,用于保存传入的文件。
public class UploadController : ApiController
{
// Enable both Get and Post so that our jquery call can send data, and get a status
[HttpGet]
[HttpPost]
public HttpResponseMessage Upload()
{
// Get a reference to the file that our jQuery sent. Even with multiple files, they will all be their own request and be the 0 index
HttpPostedFile file = HttpContext.Current.Request.Files[0];
// do something with the file in this space
if (File.Exists(HttpContext.Current.Server.MapPath("~/App_Data/uploads/test/" + file.FileName)))
{
Stream input = file.InputStream;
FileStream output = new FileStream(HttpContext.Current.Server.MapPath("~/App_Data/uploads/test/" + file.FileName), FileMode.Append);
byte[] buffer = new byte[8 * 1024];
int len;
while ((len = input.Read(buffer, 0, buffer.Length)) > 0)
{
output.Write(buffer, 0, len);
}
input.Close();
output.Close();
}
else
{
file.SaveAs(HttpContext.Current.Server.MapPath("~/App_Data/uploads/test/" + file.FileName));
}
// end of file doing
// Now we need to wire up a response so that the calling script understands what happened
HttpContext.Current.Response.ContentType = "text/plain";
var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
var result = new { name = file.FileName};
HttpContext.Current.Response.Write(serializer.Serialize(result));
HttpContext.Current.Response.StatusCode = 200;
// For compatibility with IE's "done" event we need to return a result as well as setting the context.response
return new HttpResponseMessage(HttpStatusCode.OK);
}
}
任何想法为什么我的文件被保存为 blob?谢谢!