On Tue, 25 Aug 2015 18:13:37 GMT, Louie Bacani Foronda wrote:
how do I send a file to a visitor?
example if I visit 127.0.0.1:8080/getfile/15ca691e-f886-41e0-abfd-3616655905fb.zip from the browser I should be able to download the file..is there a response function which I can use?
This is what I am trying to achieve example:void getFile(HTTPServerRequest req, HTTPServerResponse res){ string file = std.path.buildNormalizedPath("inventory/files/"~req.file); res.download(file, "200"); // the file is downloaded and a 200 server response is sent as a header }
I figured it out...
void downloadFile(HTTPServerRequest req, HTTPServerResponse res){
string s = std.path.buildNormalizedPath(std.file.getcwd()~"/data/inventory/15ca691e-f886-41e0-abfd-3616655905fb.epub");
string filename = std.path.baseName(s);
ubyte[] file = cast(ubyte[])std.file.read(s);
res.writeBody(file, 200, "application/epub+zip");
}