-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Tus: allow accessing the file in onBeforeRequest
#3977
Comments
Tus already has support for promises in
I don't think I follow, why doesn't your example with |
Yes, I meant call-backs sorry. I've read the docs and saw they do not support Promises, which is why I asked if it's possible to add.
A bit complicated because of the Bunny.net requires you to create the video file, get the id and then generate the signature. Or perhaps I just don't understand how to do it properly? Please advise. I prepared myself 2 API endpoints, one for creating the file and one for generating the signature required. |
Like I said, see the reference I quoted from the docs why we will not support that :)
This is not a place for support on how to use Bunny.net. Could you explain what is missing on the Uppy side, in particular, you want to add headings per file, which you do here: async onBeforeRequest (req) {
console.log('onBeforeRequest: ', req);
const { AuthorizationSignature, AuthorizationExpire, VideoId, LibraryId }= await GetSignature(); // api call
req.setHeader('AuthorizationSignature', AuthorizationSignature);
req.setHeader('AuthorizationExpire', AuthorizationExpire);
req.setHeader('VideoId', VideoId); // the GUID returned after "preparing" (creating) the video
req.setHeader('LibraryId', 54460); // fixed or whatever you'd like
}, Why is this not enough? |
I will set aside the Promises for now. Regarding headers, maybe I have not explained myself properly (which I do many times).
In essence, I need to make 2 requests for each file added: 1. Create video and 2. Create signature. The append the headers to each file before uploading. I hope that clarifies the challenge I am facing. |
Have you tried |
Yeah I tried, it returns the XMLHttpRequest but I cannot see anything about the file. So far the only part which gives me file information is onBeforeUpload, but this comes with the problem of not being async and not being able to set headers per file. Not sure what to do with this scenario. |
Ok, so I've found a solution here: https://community.transloadit.com/t/uppy-tus-add-unique-headers-per-file/15048 However, this is not async so I'm not sure what happens if I make 2x API calls inside it. Need to test, but probably won't be pretty. |
After testing, it's not a viable solution. onBeforeRequest seems the only solution, but there is no access to the files so back to square one. |
Alright, I see the problem and I think we can add the |
onBeforeRequest
Unfortunately there is a weird bug going on, it seems that if I attempt to upload 1 file, it gets uploaded 3 times for some reason. |
This is the chain of events that happen:
Tries again: 1,2,3.. Tries again: 1,2,3.. Upon peeking into https://docs.bunny.net/reference/tus-resumable-uploads#upload-example-javascript I can see something about upload.findPreviousUploads() but I doubt this is the problem. My idea is that the initial HEAD request to an invalid /tusupload/id is the cause. I don't understand how to prevent this behaviour, do you have any clues? |
Forgot to mention that 3 videos get "created" but only one gets actually uploaded. Per file. |
Everything you're describing is according to the spec of tus. The initial |
As per your comment, the docs say: "At first, the client sends a POST request to the server to initiate the upload.". There is no POST sent from the client, instead a direct HEAD request is sent. I don't understand what the heck are with your sarcastic comments instead of actually looking into the issue. From the get go you were sarcastic until proven otherwise. I spend time and effort writing stuff so you can improve the library, I don't need your medieval sarcasm, nobody does. If you want to look at the issue and improve your library fine, if not good luck. I`m not wasting my time anymore. |
Sir, let one thing be very clear, you are using a free product, you don't have any right to customer support. This is all based on best effort. You started your issue of with:
We are not waiters at a restaurant serving at your command. Open source software is driven by the community and kindness. You then resumed to ignore my answers with references to docs and asked the same question again. Now, once again, you didn't read my comment:
Two things can happen now, you don't use this awesome product that takes away massive complexity you'd have to write yourself, or we start again like this:
Lastly, It wasn't my intent to come off as sarcastic or uncaring, sorry if that happened. |
onBeforeRequest is triggered for each HTTP request made by the TUS protocol (including each chunk of the file being uploaded).. so your api request to create a videoId will fire multiple times (for each chunk of your file).. I am facing this issue right now and not sure how to resolve it.. |
Could it be that you are setting a |
by design @jonathanlal Try caching the external request so it's not called multiple times per request, something like this: let file_headers = {};
const uppy = new Uppy()
.use(Tus, {
endpoint: TUS_ENDPOINT,
async onBeforeRequest(req, file) {
if (!file_headers[file.id]) {
file_headers[file.id] = await someExternalHttpCall(file);
}
const { signature, expiration_time, video_guid, library_id } = file_headers[file.id];
req.setHeader('AuthorizationSignature', signature);
req.setHeader('AuthorizationExpire', expiration_time);
req.setHeader('VideoId', video_guid);
req.setHeader('LibraryId', library_id);
}
}); |
Initial checklist
Problem
For people that tend to use Bunny.net for hosting media, they offer a TUS endpoint. However, each file uploaded must have some headers set and these must be per file basis. https://docs.bunny.net/reference/tus-resumable-uploads#upload-example-javascript
I may be a total noob at this, but at the moment I cannot see a way to set these headers for multiple files.
When using Bunny.net, you first have to "create" the video file, so for this purpose there are some options:
Example authorization code for single file:
Solution
Well for starters, I would like to have async/await support in
onBefore*
callbacks so you can await for an api response to "prepare" the video and get the GUID.Then I would like to have the ability to set these headers for each file, as explained above.
I`m not sure how to achieve this, if you already have a solution please do share.
Alternatives
I am really not sure what alternatives there are, please do advise.
The text was updated successfully, but these errors were encountered: