Ability to upload a file using clientide script on the client system

We are currently working on providing the user with the ability to download MP3 files. We are developing an application that fully runs on the local system that a server is not required.

But downloading mp3 files does not work in most browsers. It is opened by built-in media players in most browsers.

We tested the solutions for this as we get answers like setting a "content-disposition" using a server-side header or using PHP or ASP scripts to make it downloadable.

I also checked the jquery filedownload.js plugin. which also had a section, such as setting content and set-cookie.

So, I want to know if it is possible to create a link to download files (for MP3) *, compatible for all browsers using only client scripts like Javascript or jQuery.

Important Note:

In fact, the process does not download the file from the server, but from the client system itself.

This MP3 file must be copied from one place (Directory) to another place in the client system.

+6
source share
1 answer

This solution requires XHR2 browser support (http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html)

It will download the MP3 in blob, and then create a URL with which you can access the blob. During this process, you can override Mimetype for what you need.

window.URL = window.URL || window.webkitURL; var xhr = new XMLHttpRequest(); xhr.open('GET', 'http://robtowns.com/music/blind_willie.mp3', true); xhr.responseType = 'blob'; xhr.overrideMimeType('application/octet-stream'); xhr.onload = function(e) { if (this.status == 200) { var blob = this.response; $('#link').html('<a href="'+window.URL.createObjectURL(blob)+'">Download</a>'); } }; xhr.send(); 

The JSfiddle example requires that you disable web security in your browser to allow cross-domain request. http://jsfiddle.net/D2DzR/3/

+2
source

All Articles