nbd-wtf / nostr-tools

Tools for developing Nostr clients.
The Unlicense
685 stars 188 forks source link

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

Closed syusui-s closed 1 month ago

syusui-s commented 2 months ago

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