我正在使用Azure Web角色(而不是MVC)ApiController来接收FineUploader请求。它工作正常(!) - 文件成功上传 - 除了响应似乎不是客户期望的。我在控制器中使用PostFormData
方法并调整了ASP.Net MVC示例代码。
这是服务器端代码:
public async Task<HttpResponseMessage> PostFormData()
{
if (!Request.Content.IsMimeMultipartContent())
{
throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
}
string root = HttpContext.Current.Server.MapPath("~/App_Data");
var provider = new MultipartFormDataStreamProvider(root);
try
{
await Request.Content.ReadAsMultipartAsync(provider);
// Show all the key-value pairs.
foreach (var key in provider.FormData.AllKeys)
{
foreach (var val in provider.FormData.GetValues(key))
{
Trace.WriteLine(string.Format("{0}: {1}", key, val));
}
}
//what should this be?
HttpResponseMessage hm= Request.CreateResponse(HttpStatusCode.OK, new FineUploaderResult(true, new { extraInformation = 12345 }));
return hm;
}
catch (System.Exception e)
{
return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e);
}
}
我尝试过JSON序列化FineUploaderResult
无效,并且尝试将该类的成员公开,以便JsonConvert.SerializeObject()
包含它们。但是客户端不喜欢这样的东西。
编辑:这是Chrome的控制台日志:
[Fine Uploader 5.16.0] Sending simple upload request for 0 fine-uploader.js:162
[Fine Uploader 5.16.0] xhr - server response received for 0 fine-uploader.js:162
[Fine Uploader 5.16.0] responseText = {} fine-uploader.js:162
[Fine Uploader 5.16.0] Received response status 200 with body: {} fine-uploader.js:162
[Fine Uploader 5.16.0] Simple upload request failed for 0