I am doing a small project in ASP.NET Core (backend) and VueJs (frontend) the communication is by axios.
I want to send a PDF file to a local path on the server. And show it in a new window.
I've been looking for information for a couple of days and I only get more confused. This is the closest I've ever been, and I honestly don't know what I'm doing :(
(I apologize for my English)
VueJS & Vuetify
this.$proxies.menusProxy
.getFileStream(
this.eitem.identificador,
{
params: {
file: "Clientes.pdf",
},
},
)
.then((x) => {
console.log("Done: ", x);
})
.catch((x) => {
console.log("Error: ", x);
});
})
.catch((x) => {});
ASP.NET
public async Task<HttpResponseMessage> GetFileStream(string file)
{
var uploads = Path.Combine("c:\\Shared\\06W03R0821105PLAE1\\"+file);
MemoryStream responseStream = new MemoryStream();
Stream fileStream = System.IO.File.Open(uploads, FileMode.Open);
fileStream.CopyTo(responseStream);
fileStream.Close();
responseStream.Position = 0;
HttpResponseMessage response = new HttpResponseMessage();
response.StatusCode = HttpStatusCode.OK;
response.Content = new StreamContent(responseStream);
string contentDisposition = string.Concat("attachment; filename=", file);
response.Content.Headers.ContentDisposition =
ContentDispositionHeaderValue.Parse(contentDisposition);
return response;
}
Console response:
Thank you very much to all