I am trying to use ServiceStack as an endpoint of Fine Uploader to upload some files. Because of a nasty behaviour with IE if the response is set to content type json/application ie prompts to download the rseponse as reported here:
IE tries to download json response while submitting jQuery multipart form data containing file
How can I force ServiceStack to respond as text/plain. I am trying this:
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};
}
}
But Service stack when using the endpoint:
/api/UploadFile?format=json
Still returns the content type as application/json
Any Ideas?
Thanks
If you just want to return a plain/text
string, you need to also return a string as seen in this example. Because it's a POCO object you want to serialize it first (assuming 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();
}
}
Otherwise you can just return a string literal directly, e.g:
return "{Success:true}";