Hi all, I’m working on a standalone app where the user can see a list of ".wav"
files from a folder and click an “upload” button to store them online. It works like this: when the user clicks “upload”, first we get a S3 pre-signed upload URL and then do a PUT request to upload the file.
The problem: the file is uploaded (right size etc.), but something is wrong with the formatting/encoding i.e. the downloaded wav
contains some extra content at the top (visible by opening it as raw text):
...
ffa72d93b3efa72e310321a7335ab8113812d5651a3428908543f2692bd97167
--2133920663baa07f
Content-Disposition: form-data; name="X-Amz-SignedHeaders"
host
--2133920663baa07f
Content-Disposition: form-data; name="file"; filename="Input 1.wav"
Content-Type: audio/x-wav
Content-Transfer-Encoding: binary
...
Now, the advice on SO etc. seems to be “don’t send any extra header (and in particular nothing that has to do with form-data, content-disposition etc.) - just send the file to upload in the body and nothing else”.
That made me think: am I doing the right thing in JUCE? Maybe I’m using the wrong function call?
I’m currently using URL::withFileToUpload
to attach the file:
auto uploadUrl = URL (uploadUrlForThisFile).withFileToUpload ("file", f, "audio/x-wav"); // attach the file
followed by something like this:
auto inputStreamOptions = URL::InputStreamOptions (URL::ParameterHandling::inAddress)
.withHttpRequestCmd ("PUT")
//.withExtraHeaders ("Content-Type: audio/x-wav")
.withStatusCode(&statusCode)
.withResponseHeaders(&responseHeaders);
if (auto inputStream = uploadUrl.createInputStream (inputStreamOptions)) {...}
I’ve been looking at the source for URL::withFileToUpload
and it seems that “form-data” etc. are added there, in URL
itself…
So I was wondering…
- am I attaching the file in the wrong way? what am I doing wrong?
- has anyone else had a similar experience and can share any insight?
- is it true that the problem is the presence of those headers or are we looking at it from the wrong angle?
Thanks in advance for any input!