-
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
Multipart upload: Changing Tus header "on the fly" doesn't change headers in PATCH requests #3434
Comments
I have integrated this comment in the original issue description 👆 |
When looking into That leads me to the conclusion that the upload is somehow not taking this field into consideration 🤷 |
I have found a solution that works for me:
I would still consider this a bug though. Of course if you see it differently, you may close this issue. |
Hello everyone, I also want to thank your team for everything you have done with uppy and tus. I have the same problem. @nebomilic could you maybe explain in detail how did you fix your problem. I can't solve it the way you solved it. There is a list of "uploaders" from the plugin but they do not have any fields and in your example there seems to be an "uploader.options" field. When I loop through the forEach loop the "uploader" is empty. Could you maybe elaborate more? As @nebomilic said the setOptions doesn't work when you want to set the refreshed token. One more question for @nebomilic or someone who can answer is how can I stop the upload when there is an upload error? What I want to do is stop the upload when the access token expires, refresh the token, and then continue the upload. I have tried using the event "upload-error" with the prefix "once" but it returns undefined. I have tried many solutions but I was not successful. |
Hi @BoreBalboa 👋 I am not sure, but I think uploaders are not null when actual upload is in progress. The code I posted above is the actual code I am using in my app, the only part missing is that it's being executed inside of an I hope this helps 😊 |
Hi, Thanks for trying to help. I can't seem to make it work. Do you stop the upload on an error? |
In our codebase we do not stop upload programatically, uppy and tus take care of this. |
I use the useUppy hook to initialize uppy. In the code below I set the Tus plugin and my token comes from local storage.
When I log out "Object.values(uppy2.getPlugin('Tus').uploaders)" I get an array filled with null values. Are you maybe setting the Tus plugin in a different way? |
I am indeed not using The question here is at which point are you logging Is it before the upload starts or during the upload. I would recommend you log In my case |
@nebomilic Thank you for your help I fixed my problem with your solution. It indeed does work as you said. I also hope in the future |
Hi, I updated the docs in #3720 and the best way to dynamically change headers is in the Example: import Uppy from '@uppy/core'
import Tus from '@uppy/tus'
new Uppy().use(Tus, { endpoint: '', onBeforeRequest, onShouldRetry, onAfterResponse })
async function onBeforeRequest (req) {
const token = await getAuthToken()
req.setHeader('Authorization', `Bearer ${token}`)
}
function onShouldRetry (err, retryAttempt, options, next) {
if (err?.originalResponse?.getStatus() === 401) {
return true
}
return next(err)
}
async function onAfterResponse (req, res) {
if (res.getStatus() === 401) {
await refreshAuthToken()
}
} I think this is the way it should be done so closing this. But we can still discuss if necessary. |
Hey there 👋
I will just add to what has been written many times before: great work with uppy and tus 👏
Maybe someone here can help me figure out whether I am facing a real issue or it is just my ignorance.
I am using@uppy/core: 1.20.0
with@uppy/tus: 1.9.2
(so last stable version 1).I have reproduced this with both
@uppy/core: 1.20.0
with@uppy/tus: 1.9.2
, and@uppy/core: 2.1.4
with@uppy/tus: 2.2.0
.The situation at hand is that I have a multipart upload enabled.
Furthermore, upload is authenticated, so I am sending an access token with the header.
The access token is refreshed every 5 minutes, but upload can take longer than that.
That means that token can change between two chunks of the same file.
To update the header on the fly, whenever the session token changes I am doing:
Nevertheless, PATCH requests have all the same token and for that reason at some point I get an 401.
Any ideas with this?
Thanks a lot 🙏
The text was updated successfully, but these errors were encountered: