I'm zipping multiple files via a Web API endpoint which I then download to my browser. Until the very last step, I can see that the zip file has a filename and that its size is set but for some reason, when downloaded, it comes back as a 1Kb file.
I've saved the binary array that contains the zip file to my local drive before returning it back to the browser via the Web API and it is indeed correct. I can open the zip file and see its content, so I'm not sure what's causing it the problem.
Clearly not the zipping since I can save it locally and it is correct, so I can only assume it has must be something with the EndPoint, but what? I use a custom IHttpActionResult:
public Task<HttpResponseMessage> ExecuteAsync(CancellationToken cancellationToken)
{
HttpResponseMessage response = new HttpResponseMessage();
var filename = this.Document.GetFilename();
var mimeType = MimeMapping.GetMimeMapping(filename);
response.Content = new StreamContent(new MemoryStream(this.Document.ToData()));
response.Content.Headers.ContentLength = this.Document.Data.Length;
response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
{
FileName = filename
};
response.Content.Headers.ContentType = new MediaTypeHeaderValue(mimeType);
return Task.FromResult(response);
}
and it looks fine to me and the odd thing is that if I download a document such as MS Word or other, it download just fine using custom IHttpActionResult and same endpoint.
To download the file via the Web API and JQuery, I found the following article:
DOWNLOAD FILE WITH JQUERY AND WEB API 2.0 IHTTPACTIONRESULT
Could it be that the saving of the blob occurs before the file is fully downloaded but then why does it work for other files?
If you want me to provide any other code, let me know but if anyone has any suggestions that would be great.
Thanks.
UPDATE-1:
Unlike previously stated, my single file download such as MS Word no longer work either and also generate a 1kb file instead of the relevant file. Something has changed but I'm not sure what yet. I will post an update when I find out.