URL withFileToUpload from memory?

Is it possible to somehow send a file directly from memory?  I see that withFileToUpload accepts only File objects, which seem to require a file on disk.  In cases where I already have the file in memory (and not on disk), it's less than ideal to have to write it to disk in order to send it along with a URL request.


does it use a stream internally. perhaps you can tap into that and use a memory stream?


Good request.. Looking at the URL class, it did need a bit of tidying-up in that department, so I've added this now. Let me know if you have any problems!

Hi, I seem to have problems with the new code indeed:

code compiled with earlier versions of JUCE works correctly when sending a ordinary file towards the server using a POST request (with a bunch of other parameters, but no custom POST data).

After this change, something seems to have benn broken because the server is now replying "500 Internal server error".

If I remove the .withFileUpload() part, that error doesn't come up, but obviously the file isn't being sent

The commit I'm referring to is this: https://github.com/julianstorer/JUCE/commit/bcec7819914eccc60742c402276ffc67e0f96a9d

I can't think of a way I could test or fix this without being able to reproduce it..

Do you have a code snippet + URL I could use that would let me see the problem?

I found the culprit right now: the problem happens only when there are both parameters AND files to be uploaded.

In that case, the parameters should be embedded in the message as parts of the multipart body, but at the top of URL::createHeadersAndPostData() the following line also adds them "inline" and the server gets confused because that messes up the structure of the mutlipart message.

    data << URLHelpers::getMangledParameters (*this);

The solution is to move the mentioned line only in the "else" branch of the if in the method, the one that's taken only when there are no files to be sent. In that case, it seems it's ok to mangle the parameters inside the message.

Thanks - should be ok now.

Seems to be working ok now, thanks.