Fine Uploader和ServiceStack设置响应标头

时间:2013-04-12 08:50:02

标签: javascript file-upload servicestack fine-uploader

我正在尝试使用ServiceStack作为Fine Uploader的端点来上传一些文件。如果将响应设置为内容类型为json / application,则会出现IE的讨厌行为,即提示下载此处报告的响应:

IE tries to download json response while submitting jQuery multipart form data containing file

如何强制ServiceStack以text / plain方式响应。我正在尝试这个:

 public class UploadFileService : Service
    {
        [AddHeader(ContentType = "text/plain")]
        public object Any(UploadFile request)
        {
            foreach (var uploadedFile in base.RequestContext.Files)
            {
                var test = uploadedFile.FileName;
            }
            return new UploadFileResponse{ Success = true};
        }
    }

但使用端点时的服务堆栈:

/api/UploadFile?format=json

仍然将内容类型作为application / json

返回

任何想法?

由于

1 个答案:

答案 0 :(得分:3)

如果您只想返回plain/text字符串,则还需要返回字符串as seen in this example。因为它是POCO对象,所以首先要对它进行序列化(假设为JSON):

public class UploadFileService : Service
{
    [AddHeader(ContentType = "text/plain")]
    public object Any(UploadFile request)
    {
        foreach (var uploadedFile in base.RequestContext.Files)
        {
            var test = uploadedFile.FileName;
        }
        var dto = new UploadFileResponse { Success = true };
        return dto.ToJson();           
    }
}

否则你可以直接返回一个字符串文字,例如:

return "{Success:true}";