Could anybody point out how to use the new class ofURLFileLoader to asynchronously save a file from a URL?
I want to save a file I have a file in a local server at lets say http://192.168.1.15:8080/myFile.txt
How I have to handle the int returned by ofURLFileLoader::saveAsync method (or the ofHttpResponse object returned by ofURLFileLoader::saveTo method)?
it’s easier to just use the functions ofSaveURLAsync(url,path). the returned int is the id of the request in case you want to remove it in case it keeps failing and also to identify when it has finished (although you can also use the url for that)
If you want to get a notification when it ends downloading add a method like:
void testApp::urlResponse(ofHttpResponse & response);
and register to the notification like:
Thank you for your answer Arturo.
I have already tryed that functions but I haven’t seen how to set the parameters.
For example, for an image in the local server at:
I can load it directly with:
But as I don’t want to block the app while loading some new images from the server I try this:
I’ve also tried:
as I am not very sure aboyt the path parameter use.
Probably I am missunderstanding the use of this function (I was expecting it to save the file in the /data folder of the OF app).
if you use the / at the beginning of a path it’ll save it to the root of the file system where you probably don’t even have permissions to write.
Also if you want to load images asynchronously take a look at the ofxThreadedImageLoader
Thanks again, Arturo.
You are right, the problem was with the absolute path.
What I see now is that with both ofSaveURLAsync() and ofSaveURLTo() I can save poperly text files but when I save binary files they seem to be somehow corrupted.
Is there anything else to set to transfer binary files?
are you in windows? there’s a problem with binary files someone discovered in windows some days ago, we are trying to solve it, will upload the changes to github and post in the forum as soon as it’s fixed but it seems it’s a problem with setting the binary mode as ios::binary instead of ios_base::binary in ofFile
Yes, I am under Windows 7/Codeblocks.
I will follow the changes to fix the problems with binary files.
Thank you again.