Setting autorevoke for url.createObjectURL

I am trying to create blob in Javascript for file feed. However, the link created with the help window.URL.createObjectURL(blob)

becomes invalid over time. I want to be able to create a link that is valid as long as the page is open. Online I saw that the autoRevoke parameter was set to true, so this led me to believe that the URL is being revoked when not actively used. I tried setting it to false, but I am getting a TypeError.

Here is the code:

var res = xhr.response;
var blob = new Blob([res]);
var url = window.URL.createObjectURL(blob, {autoRevoke : false}); 

      

Here is the error:

Uncaught TypeError: Type error background.js:52

      

How can I prevent an invalid blob url?

+3


source to share


1 answer


If you save the blob to the filesystem using the API described here: http://www.html5rocks.com/en/tutorials/file/filesystem/

You can create a file system url that will persist. This solution has the disadvantage of prompting the user to approve the saved files.



Can you tell us more about this feature, how the user will see it? What are you referring to?

In response to your comment: I recommend keeping the input element in the DOM as long as you want to keep a link to the file's contents. If you are linking to content, you can create a link that calls a function with a unique ID of the input element. This function generates a blob url on demand and redirects the browser to that url. If you are using the url like img src or something similar, it is possible that your app has a user experience that still allows you to create a blob url on demand.

0


source







All Articles