We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Download file
Page Index Toggle Pages: 1
Download file (Read 802 times)
Download file
Feb 18th, 2010, 6:06am
 
Hello i want to download file on web server so i try the following code:


String[] data;

void setup() {
 size(200, 200);
 background(50);
 fill(200);
data = loadStrings("http://jmleau.com/000%20rep%20hors%20site/sci%20la%20claveliere/colloc%20pour%20site.odt");
saveStrings("tst.odt",data);
}



The problem is that the file "tst.odt" i save is quit longer then the file on server and i can't open this file (it is different from the file on server).

I tried with zip file and it is the same result i can't use it.

is somebody have an idee ?
Re: Download file
Reply #1 - Feb 18th, 2010, 6:12am
 
What does the tst.odt look like when you open it with a text editor?

If you see something starting with "<!DOCTYPE html" then there are chances you are retrieving a 404 error page instead of your file.
Re: Download file
Reply #2 - Feb 18th, 2010, 6:37am
 
use loadBytes() and saveBytes() if you're just saving a binary file. or better yet, use saveStream():
http://processing.org/reference/saveStream_.html

the more advanced explanation: an .odt file is a zip archive with the contents of an openoffice doc. if you load it as string data on windows, it'll convert each \n (newline character) to \r\n (windows new line) when saving (making the file larger). my guess is that's what's happening, but the bottom line is that you shouldn't use loadStrings().
Re: Download file
Reply #3 - Feb 18th, 2010, 7:35am
 
Don't post duplicate messages in various sections, it just waste time of those making thus duplicate answers, not seeing it was already answered.
Deleted other thread.
Re: Download file
Reply #4 - Feb 19th, 2010, 2:09am
 
Thank you for your help.

It was not a 404 error.

it works well with loadStream if you know how to use this instruction because the reference is really confusing !

but i find a topic
http://processing.org/discourse/yabb2/num_1258965028.html#3

Where the syntax is well explain:
LoadStream("filename_to_save","url")

so the working code simply become

Code:

void setup() {
size(200, 200);

saveStream("tst.odt","http://jmleau.com/000%20rep%20hors%20site/sci%20la%20claveliere/colloc%20pour%20site.odt");

}


i consider this topic is resolved.
Thanks again
Page Index Toggle Pages: 1