-
Notifications
You must be signed in to change notification settings - Fork 80
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
How to get PUT request status code when using usePresignedUpload
?
#132
Comments
Hey there! Thanks for the issue! Quick question: Do you need the status code, or is knowing if the upload was successful or not enough? |
Well, I was hoping that the app code would determine if the upload was successful or not by using the But yeah, just knowing somehow that the upload was successful would be enough. Maybe this info could be obtained from each file from |
Wait a sec... I think there's a small bug here: https://github.com/ryanto/next-s3-upload/blob/master/packages/next-s3-upload/src/hooks/use-presigned-upload.ts#L20 When This is how I suppose it should work: xhr.onload = () => {
if (xhr.status >= 200 && xhr.status < 300) { // Lib considers 4xx & 5xx as errors
resolve(xhr);
} else {
reject(xhr);
}
};
xhr.onerror = () => reject(xhr.statusText); I know this is unrelated to my original question but it was bugging me. 😅 If you preffer, I can create a new issue. |
Ha nice catch! Absolutely a bug. No need for new issue, but if you want to PR a fix go for it! |
Oh, cool! Let me give it a shot. Do you mind if in the PR I include the bug fix and my suggestion for provingding the |
I think we should skip the xhr object for now, just because I'm not sure I want to expose the xhr object forever. In the future we might switch this to If the promise is rejecting correctly then you'll know if an upload worked: try {
await uploadToS3(...);
} catch(e) {
console.error("upload failed");
} |
Hey @williamrjribeiro thanks again for spotting that bug and getting it fixed in the PR! I really appreciate it. I think for the status code I'd rather not expose it at this point. There's a few reasons, but in no particular order:
I'm always open to having my mind changed, so if you have use cases that are only solved by knowing the status please let me know. Also thanks again for that bugfix! Super happy we got one that one solved 😄 |
Hello there. 👋
I'm dealing with a very simple scenario that I'm unable to overcome.
Our app uploads files using pre-signed URLs and we encountered a bug where all
PUT
requests to the bucket were resulting in403
due to some configuration error. Our UI was not dealing with this kind of error and was wrongly showing "upload success" messages.Now that we have identified the root cause of the problem, I'm not able to figure out how to get the status code of the
PUT
request performed byusePresignedUpload
.From what I've seen in the code, one of the easiest solutions would be to pass the
xhr
reference toresolve
andreject
calls:https://github.com/ryanto/next-s3-upload/blob/master/packages/next-s3-upload/src/hooks/use-presigned-upload.ts#L21
But please let me know if I overlooked something.
Cheers!
The text was updated successfully, but these errors were encountered: