c# - Azure blob storage download file instead of opening in the browser -


i uploading files azure blob storage using code, container cloudblobcontainer

    public void savefile(string blobpath, stream stream)     {         stream.seek(0, seekorigin.begin);         cloudblockblob blockblob = container.getblockblobreference(virtualpath);          blockblob.properties.contentdisposition =  "attachment; filename=" + path.getfilename(virtualpath);          blockblob.uploadfromstream(stream);     } 

then when user clicks on file in web page trying trigger download prompted either save/open file. calling action returns redirect blob url.

    public actionresult loadfile(string path)     {             string url = storagemanager.getbloburlfromname(path);         return redirect(url);     } 

the issue open files in browser e.g. user redirect away site , shown .jpg file in browser when expecting them stay on page start downloading file.

one way achieve want mvc action fetch image blob storage , return file, ie:

public actionresult loadfile(string path) {         bytearray imagebytes = ....get img blob storage     return file(bytearray, "image/png", "filename.ext"); } 

Comments

Popular posts from this blog

gcc - MinGW's ld cannot perform PE operations on non PE output file -

timeout - Handshake_timeout on RabbitMQ using python and pika from remote vm -

c# - Search and Add Comment with OpenXML for Word -