I am going to use Google app engine Blobstore to store my uploaded files. File type can be anything (.txt,.pdf,.docx etc)
I have written following servlet to download stored files in Google app engine Blobstore.
public class Serve extends HttpServlet {
private BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws IOException {
BlobKey blobKey = new BlobKey(req.getParameter("blob-key"));
blobstoreService.serve(blobKey, res);
}
}
But every time I request a file by giving a url as below,
http://127.0.0.1:8888/serve?blob-key=DEHQ3U_2wtUdEL7XPI434Q
file is downloaded nicely. But no extension for file. And name of the file is always ‘serve’
What should I do to download the uploaded file with the original name of the file?
Thanks,
I know python has a
send_asoption that automatically sets the filename for the response, but I think in Java you will have to add aContent-Dispositionheader to the response like:The BlobInfo for your blob keeps the original filename and you can fetch it via
getFilename