0

During implementation of file transfer use case through WebRTC protocol, i am recieving data from queue at reciever end in some variables but unable to use that. Through some digging, i came to know that it can be done using Blob, code snippet that i used :

var data=reciever.dequeue();
if(data)
{ var blob = new Blob(_base64ToArrayBuffer(data), {type: 'text/plain'});
  // need to know how to proceed now?
}

file is need to be saved in local system.Thanks in advance.

3
  • Do you mean you want the browser to download this file and save it? Commented Nov 6, 2014 at 10:30
  • yes,on the recieving end browser sould download the file or create download link for the same. Commented Nov 6, 2014 at 14:32
  • Can you check my answer below, I think this can satisfy your requirement. Commented Nov 6, 2014 at 15:02

1 Answer 1

1

You can create a temp anchor element element and append it to document.body, trigger click event. Done.

Here is the demo code:

var url = objectURL = URL.createObjectURL(blob); //your blob object here
var anchor = document.createElement("a");
anchor.href = url;
anchor.download = "YourFileName";
anchor.click(); //This will trigger browser download event.

Here is document about blob to URL.

Here is the blob document.

Hope this works. : )

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.