Skip to content
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

file.getBlobURL w/o callback #1625

Closed
tomasparks opened this issue May 8, 2019 · 5 comments
Closed

file.getBlobURL w/o callback #1625

tomasparks opened this issue May 8, 2019 · 5 comments

Comments

@tomasparks
Copy link

@tomasparks tomasparks commented May 8, 2019

I have a function that calls BlobUrlFromUrl(),
in that function, I call file.getBlobURL() but, before I get a response the function has returned cause undefined errors in the string :(

var xml = '<xml><krpano><scene id="' + pano.id + '" title="' + pano.title + '" >' xml = xml + '<preview url="' + BlobUrlFromUrl(files.preview, rootUrl) + '" />' xml = xml + '<image>' xml = xml + '<left url="' + BlobUrlFromUrl(files.left, rootUrl) + '"/>' xml = xml + '<front url="' + BlobUrlFromUrl(files.front, rootUrl) + '"/>' xml = xml + '<right url="' + BlobUrlFromUrl(files.right, rootUrl) + '"/>' xml = xml + '<back url="' + BlobUrlFromUrl(files.back, rootUrl) + '"/>' xml = xml + '<up url="' + BlobUrlFromUrl(files.up, rootUrl) + '"/>' xml = xml + '<down url="' + BlobUrlFromUrl(files.down, rootUrl) + '"/>' xml = xml + '</image></scene></krpano>';

function BlobUrlFromUrl(url,rootUrl) { torrent.files.forEach(function (file) { if ((file.path) == (rootUrl+'/'+url)) { file.getBlobURL(function (err, bloburl) {if (err) return log(err.message);log('file.getBlobURL() '+bloburl);success: bloburl;}); // log('torrent.files(): '+ bloburl); } }) }

runtime: https://tomasparks.name/krpano-and-webtorrent/index.html
source code: https://github.com/tomasparks/krpano-and-webtorrent

@alxhotel

This comment has been minimized.

Copy link
Member

@alxhotel alxhotel commented May 8, 2019

You can only get the Blob URL after the file is fully downloaded.

Try using the event done:

torrent.on('done', function () {
  // Here
})
@jimmywarting

This comment has been minimized.

Copy link
Contributor

@jimmywarting jimmywarting commented May 8, 2019

please wrap your code with 3 backticket so it becomes readable

Skärmavbild 2019-05-08 kl  15 51 51

also, whatsup with ;success: bloburl;?

@tomasparks

This comment has been minimized.

Copy link
Author

@tomasparks tomasparks commented May 8, 2019

also, whatsup with ;success: bloburl;?

it was a failed experiment that I didn't clean up

@jimmywarting

This comment has been minimized.

Copy link
Contributor

@jimmywarting jimmywarting commented May 8, 2019

you don't have to wait for the done event to finish all files as getBlobURL can be called straight await. however the getBlobURL is async so you need to get the blob urls before creating the xml, the alternative is that you create the xml and insert the blob url afterwards

something like this (untested):

file.getBlobURL(function(err, url) {
  xml.queryElement('left').setAttribute('src', url)
})
@tomasparks

This comment has been minimized.

Copy link
Author

@tomasparks tomasparks commented May 9, 2019

thanks 😞

@tomasparks tomasparks closed this May 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.