In my app, it is possible to download a file from the internet.
So, for example I’d pass http://ardownload.adobe.com/pub/adobe/reader/win/9.x/9.0/enu/AdbeRdr90_en_US.exe to my function and it downloads the file from the URL to my computer.
I would like to be able to show the download progress, but this seams no possible to do because the InputStream created by the URL class shows me -1 as length (length unknown).
How can I find out the length of that stream?
It doesn’t currently support that - it might be possible to pull the info out of the http header info, though…
i had the same problem (but with uploads, it doesn’t matter witch way you want to transfer data)
i used curl, it embeds nicely and cleanly with juce, no need for extrnal dependencies (unless you want some, like SSH or SSL support).
here is an example:
the whole project:
Thanks atom! But I think I’d prefer not to use another library in my project. I’ll see what I can do…
i used libcurl for some time now and it works great, supports all the protocols out of the box, you just add the files to your project (no lib dlls or other stuff) build everywhere and is very well documented.
i was kinda hoping jules would consider using curl for his URL class, it would gain a lot more functionality.
I hear you, but is it LGPL?
Libcurl is MIT/X, which means that you can do what ever you want as long as you include a copyright notice:
Mmm… but should you do it, beware of platform issues as curl uses fopen to verify a file (doing multipart posts) and fopen doesn’t support UTF8 on windows. So on windows, the stream callback must be used (libcurl 1.18.1). On Mac I never got the stream callback to work, so on Mac I use libcurls own file upload…
How did we conclude this discussion? Is libcurl the best way (in juce) to upload files to a server?
As JUCE now supports multipart posts (right Jules :?: ) , I suppose you don’t need anything else. We’re thinking of going back to juce::URL for that reason (and for avoiding different code on different platforms).
Yes, I did a project recently that required file uploading, so I sorted that stuff out. If you do hit any probs with it, please let me know as I’ll need to fix it!
I need to upload a file to a server. The server side cgi expects a parameter userId and the file name. I try the following code, but it’s not even able to see userId on the other end (the script doesn’t go on to see if the file has been posted yet but I am sure that wouldn’t work either. This is my first attempt at using juce for file upload and I think I’m missing something simple:
const juce::URL url = new URL(serverCgiPath);
url = &(url->withParameter(“userId”, 1));
url = &(url->withFileToUpload(“uploadfile”, myFile);
juce::InputStream input = url->createInputStream(true);
input->read((void*) buffer, 1024);
The buffer has a response from the cgi script that is sent when no userId has been set.
Also why do the different URL methods return a copy of the URL and not modify the URL itself?
I’m using libcurl as well for internet uploads/downloads. Besides giving a callback function to get the info for a progress bar, libcurl also supports http authentication, including digest, and HTTPS. The lack of support for authentication in Juce’s URL class is what led me to consider libcurl.
I posted because I hope I’m wrong and that there really is support for authentication in Juce.