Skip to content

Save to local storage does not work with local media (eg blobs). #71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
pietrop opened this issue Jan 4, 2019 · 2 comments
Closed

Save to local storage does not work with local media (eg blobs). #71

pietrop opened this issue Jan 4, 2019 · 2 comments
Assignees
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@pietrop
Copy link
Contributor

pietrop commented Jan 4, 2019

Reason is that local storage save at the moment uses the url of file as the key, and for local media the blob has different url all the time.

needs some research into alternatives eg change key to file name and not url? (for all or for blob url only?)

@pietrop pietrop added bug Something isn't working help wanted Extra attention is needed labels Jan 4, 2019
@pietrop pietrop self-assigned this Jan 4, 2019
@pietrop
Copy link
Contributor Author

pietrop commented Jan 4, 2019

Some notes of what I got so far.

TL;DR: still no viable solution.


In the demo app once the local media is uploaded we create an object url and pass that to the component.

const fileURL = URL.createObjectURL(file);

So I was looking to see if we could use the file name(as this would not change 🤞and should allow us to retrieve the corresponding transcript from local storage on page refresh) instead of the blob url, without having to pass it to the component.

after a bit of exploration I had figured out that you can convert an object url back into a blob

var blob = null;
var xhr = new XMLHttpRequest(); 
xhr.open("GET",  window.fileURL);  // `window.fileURL` is the url to convert
xhr.responseType = "blob";//force the HTTP response, response-type header to be blob
xhr.onload = function() 
{
    blob = xhr.response;//xhr.response is now a blob object
}
xhr.send();

However the problem is that a blob by its nature only has two attributes, size and type

{size: 85047555, type: "video/mp4"}

as explained here on stackoverflow you could then convert this into a file

var file = new File([blob], "name");

But it doesn't seem possible to get the original file name of an object url even after converting it to a blob as it is not stored in the blob.

@pietrop
Copy link
Contributor Author

pietrop commented Jan 14, 2019

fixed in this PR #72

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant