2

I have a .NET web application that houses a large number of downloadable documents. I want to move these files offsite to Azure storage. However, given a particular file's URL, I need a way to download it from the client browser (using Javascript of course). The behavior I am seeking is for the browser's 'Save File As' functionality to invoke allowing the user to save the file to their local computer.

I have the following code attempt that isn't working. I am using a script tag b/c that is the only way I can get around the cross domain scripting issue. However, when looking with Fiddler, the request is never even attempted. It's my understanding that setting the .src property should invoke the download.

var script = document.createElement('script');
script.type = 'application/pdf';
script.src = 'http://myazureaccount.com/myPDFfile.pdf';

Can someone show me a way to accomplish this? There might not be a way to do it. Also I don't want to run any sort of server side code in Azure. I just want to use it as an external file store.

SliverNinja - MSFT
  • 31,051
  • 11
  • 110
  • 173
John Livermore
  • 30,235
  • 44
  • 126
  • 216
  • This post seems to address that. http://stackoverflow.com/questions/4799669/trigger-a-browsers-save-as-dialog-via-javascript-using-only-on-page-data – dysruption May 17 '13 at 18:16
  • 1
    Close, but that post discusses working with data already on the page. Using Javascript, I am needing to invoke a file download of a file located on a server different from mine. – John Livermore May 17 '13 at 19:12

1 Answers1

1

You should use a Custom Domain for your Azure Storage account so it comes from the same domain (e.g. files.mydomain.com). This will solve the cross-site scripting (XSS) issue.

SliverNinja - MSFT
  • 31,051
  • 11
  • 110
  • 173