postman add header to uploaded file
When I'm trying to upload a file to Backblaze B2 (storage provider) using Postman, a header and footer is being added to all files and seems to be damaged and can't be opened
----------------------------114434797603440341474406
Content-Disposition: form-data; name="package.json"; filename="package.json"
Content-Type: application/json
file content
----------------------------114434797603440341474406--
That is happening only when I use form-data to upload file, and it's working fine when I use the binary method in Postman
My questions are:
- Is that header being added by Postman or the storage provider?
- Am I doing something wrong when I'm uploading?
- Is it fine to upload file from client as binary by using FileReader.readAsBinaryString() JS method
This is the C-url request I'm sending
curl --location
--request POST 'https://..........t0045' \
--header 'Authorization: 4_002..........' \
--header 'Content-Type: application/json' \
--header 'X-Bz-File-Name: package.json' \
--header 'X-Bz-Content-Sha1: do_not_verify' \
--form 'package.json=@"/path/to/file/package.json"'
Answering your questions in turn:
- That header (and footer) is being added by Postman. When you tell Postman to use form-data, you are telling it to add the header and footer to the data.
- You must specify binary when uploading to Backblaze B2 (see below).
- Yes - you should be able to use
FileReader.readAsBinaryString()
.
The docs for b2_upload_file explain that you must provide the binary file data in the HTTP message body:
The file to be uploaded is the message body and is not encoded in any way. It is not URL encoded. It is not MIME encoded.
The cURL should look like this:
curl \
-H 'Authorization: 4_002..........' \
-H 'Content-Type: application/json' \
-H 'X-Bz-File-Name: package.json' \
-H 'X-Bz-Content-Sha1: do_not_verify' \
--data-binary @"/path/to/file/package.json" \
'https://..........t0045'