The result is always a broken image. I’ve tried several image/jpeg and image/png but got always the same result.
Results can be seen here: https://webhook.site/#!/view/daf73eda-e68c-4463-9acb-1cbf9e8194de/25e1d543-e60c-4af4-9541-4ec995889c73/1
This is how the file looks after it has been sent through http.put(…). The Buffer has been converted to a JSON text representation which means the file cannot be opened as an image anymore.
For context: For this particular API we must send the image data as raw binary inside the HTTP content body. This API does neither accept files as “Content-Type: multipart/form-data” nor as Base64-endoded data in a JSON field.
could you let me know a time frame when you’ll be able to look into this?
Jason and I both confirmed that it isn’t working properly, and it has unfortunately brought my project to a sudden stop. It’s a bit frustrating since there’s no workaround within Tape.
Thanks a lot for your report, and also many thanks to @Jason for double-checking and confirming the issue. We really appreciate your support here.
We’ll take a closer look at this with priority to better understand why the image cannot be sent. As soon as we have first findings, we’ll get back to you right away here.
In the past, users also encountered issues with external APIs that expect a binary file for processing, e.g. for a Autentique signature API :
The only solution at the end of the day was providing a dedicated postFormData function in the http client library, which was used in this showcase:
That corresponds with the solution proposed by @Jason (thank you!) - but if you cannot switch to POST does not provide a solution to your issue.
What we can offer: Add a matching PUT version for that function, that should be able to send the binary file directly to your external API’s PUT endpoint using the same form data wrapper. Do you think that could be an option? As it worked for POST in the past, we would expect it to work for your case as well.
(TLDR: We found a work-around for the API that we need, but the root cause is still there.)
I am working with @Kollaborateur on this. The postFormData is sending data as “Content-Type: multipart/form-data” and not as binary.
The documentation of this particular API says to do the following:
Create an an upload request (POST request to the initializeImageUpload endpoint), you will get an image ID and upload URL.
Then do a PUT request to the upload URL with the binary image data as the content body of the HTTP request (NOT multipart/form-data).
Do a GET request for the image ID and get the status. If the status is “AVAILABLE”, then everything went well.
Our work-around: We did a lot of testing back and forth with the API in question. We now have a solution that works, but not as documented. The API in question seems to both accept PUT and POST requests and if the POST request contains a multipart/form-data with a file field called “file” - only then it will accept also POST requests.
So we have a solution to our problem now!
The addition of putFormData is a good idea and you should make a feature request out of that.
But it would not have helped in this case. With the current state of the tape “http” interface it is impossible to send a binary HTTP payload: