OK, so i try to download a memorystream with data in it, i already know the byte array i convert it to has the data in it but i dont get why my response isn't working. Wenn i press the button on the website nothing happens (well something happens, but i don't get the download...). I think all the HTTP headers must be correct, after all the research i couldnt find anything more than that.
using System.IO;
using System.Web;
using System.Net.Http;
using System.Net.Http.Headers;
namespace TranslationManager.Controller
{
[Route("api/controller")]
[ApiController]
public class Download : HttpGetAttribute
{
[HttpGet]
public HttpResponseMessage File(MemoryStream ms)
{
byte[] b = ms.ToArray();
var response = new HttpResponseMessage(System.Net.HttpStatusCode.OK);
response.Content = new ByteArrayContent(b);
//Set the Response Content Length.
response.Content.Headers.ContentLength = b.LongLength;
//Set the Content Disposition Header Value and FileName.
response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
response.Content.Headers.ContentDisposition.FileName = "file";
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
return response;
}
}
}
Aucun commentaire:
Enregistrer un commentaire