Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upfile.getBlobURL w/o callback #1625
Closed
Comments
This comment has been minimized.
This comment has been minimized.
|
You can only get the Blob URL after the file is fully downloaded. Try using the event torrent.on('done', function () {
// Here
}) |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
it was a failed experiment that I didn't clean up |
This comment has been minimized.
This comment has been minimized.
|
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)
}) |
This comment has been minimized.
This comment has been minimized.
|
thanks |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

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