I could send an image file sucessfully using Swagger or Postman where I could upload the file from the local machine. However, when I need to send a file that is saved online, I need to compose the body part of the request. I tried to encode the binary content as base64 or ASCII etc, but the received files could not be opened. When I opened in notepad, I woould just see the string of binary content expressed in UTF-8. Is there anything that I missed?
I am a nooby in API and I am more than happy to clarify any that is not clear.
The body I tried was like:
var body = '--' + boundary + '\r\n' +
'Content-Disposition: form-data; name="file"; filename="' + fileName + '"\r\n' +
'Content-Type: application/octet-stream\r\n' +
'Content-Transfer-Encoding: base64\r\n\r\n' +
binaryContent + '\r\n' +
'--' + boundary + '--';
I am not too sure what should the binaryContent look like:
if it look like "/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAI....", the received file would be just the identiacal string of "/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAI...." as if the server did not decoded it at all.
BTW, I notice that some solutions use form() function to build the body. Unfortunately, my environment does not have that function.