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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -