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

fix Content-Type bug in NIP-96 uploadFile #413

Merged
merged 1 commit into from
Jul 20, 2024

Conversation

syusui-s
Copy link
Contributor

@syusui-s syusui-s commented Jul 2, 2024

Why

The NIP-96 uploadFile has a bug. This PR fixes it.

When using fetch API along with FormData, specifying Content-Type will cause error. It is because if we specify Content-Type: multipart/form-data, the browser will send it as is without considering "boundary".

Warning: When using FormData to submit POST requests using XMLHttpRequest or the Fetch API with the multipart/form-data content type (e.g. when uploading files and blobs to the server), do not explicitly set the Content-Type header on the request. Doing so will prevent the browser from being able to set the Content-Type header with the boundary expression it will use to delimit form fields in the request body.
https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest_API/Using_FormData_Objects#sending_files_using_a_formdata_object

The browser will detect Content-Type from body and append boundary=... appropriately. We don't need to specify Content-Type.

References

@syusui-s syusui-s changed the title remove Content-Type header from NIP-96 uploadFile fix Content-Type bug in NIP-96 uploadFile Jul 17, 2024
@fiatjaf fiatjaf merged commit a87099f into nbd-wtf:master Jul 20, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants