Closed austincummings closed 9 years ago
Actually it seems it's responding with the file. But not as a download in the browser. Any idea on that?
Hi,
To force the browser to handle the response as a downloadable file, you can set the content-disposition: attachment;
header. There are some ways to do that. One option is to use an interceptor:
@app.Interceptor("/files/.*")
downloadFileInterceptor() {
app.chain.next(() => app.response.change(headers: {
"Content-Disposition": "attachment; filename=\"${app.request.url.pathSegments.last}\""
}));
}
@app.Route("/files/:filename")
Future<File> downloadFile(String filename) {
//create and return a File object
}
That way, the user can send a request to /files/report.pdf
, to download a report.pdf
file, for example.
Another option is to directly build and return a shelf.Response
object, instead of returning a file.
Let me know if that helps.
Closing this issue, but let me know if you still has problems or doubts.
Hey @luizmineo,
I need to have a route that is capable of returning a file from the file system. I currently have one that returns a
Future<File>
asnew File(filePath)
. But it seems that everytime I try to request the route it sends a completely empty response.Any help with this would be greatly appreciated.
Thanks