save file from web

832 views
Skip to first unread message

Yeorgios Kapellakis

unread,
Jul 27, 2014, 3:03:11 AM7/27/14
to mitappinv...@googlegroups.com


Hello all,

On the below code I download a file.

I get a response that the file download it, but when I try to read it I get an error that the file does not exists.

Any help on that?


Thank you,

G

phantomfoot

unread,
Jul 27, 2014, 6:12:35 AM7/27/14
to mitappinv...@googlegroups.com
Check what you are getting as your responsecode in gotfile. It should be 200 for a successful download.

Also what is the value of fileName you are getting?

SteveJG

unread,
Jul 27, 2014, 8:39:26 AM7/27/14
to

If you get a 200 response, as Steve (the other Steve) suggested, then read this to find your file.



Get()
Performs an HTTP GET request using the Url property and retrieves the response.
If the SaveResponse property is true, the response will be saved in a file and the GotFile event will be triggered. The ResponseFileName property can be used to specify the name of the file.
If the SaveResponse property is false, the GotText event will be triggered.


You have to tell your device where to store the file and give it a name.

set Web.ResponseFileName to          something like \super90Files\newXML.txt     perhaps should work.  or .xml

then when you try to read the file, you need to include the path    \super90Files\newXMLtxt  .... you can do this in one step or using a 
join  \super90files\
newXML.txt

Your device probably saved the file you wanted with an arbitrary name, some where on your device... sorry, I can not remember the default directory if you do not set Web.ResponseFileName.

Try making the changes to the blocks.. the set Web.Response....needs to preceded your request.

Regards,
Steve




Taifun

unread,
Jul 27, 2014, 10:18:58 AM7/27/14
to mitappinv...@googlegroups.com
as Phantomfoot said...
btw. you can use Do it or a label to find out the filename, which starts with /mnt/sdcard/myDirectory/myFile.txt... or /storage/emulated/myDirectory/myFile.txt

the File component however expects the path to look like this
/myDirectory/myFile.txt

which means, you will have to remove /mnt/sdcard  or /storage/emulated to be able to read the file with the File component
Taifun

Trying to push the limits of App Inventor! Snippets and Tutorials from Pura Vida Apps by Taifun.         

ReadFrom(text fileName)
Reads text from a file in storage. Prefix the filename with / to read from a specific file on the SD card. for instance /myFile.txt will read the file /sdcard/myFile.txt. To read assets packaged with an application (also works for the Companion) start the filename with // (two slashes). If a filename does not start with a slash, it will be read from the applications private storage (for packaged apps) and from /sdcard/AppInventor/data for the Companion.

Yeorgios Kapellakis

unread,
Jul 27, 2014, 11:46:48 AM7/27/14
to
Hello all,

When I download it I get a message that the file received and I have a path.

The name of the file is a <random_name>.tmp

I try your suggestions and I let you if it worked for me or not

Also I am doing the test in a real device and not in a emulator

phantomfoot

unread,
Jul 27, 2014, 4:46:30 PM7/27/14
to mitappinv...@googlegroups.com
That is most likely why, the fileName is not a full file name it is a temp file with .tmp.

A file name should be similar to Taifun's example, with a path. So have a go setting the response fileName before your call.

Yeorgios Kapellakis

unread,
Jul 28, 2014, 3:12:44 AM7/28/14
to mitappinv...@googlegroups.com
Good morning all,

Thank you for your suggestions it was really useful.

Also I found a  way to create an xml parser (at least for my case) by using a tutorial I found about parsing some strings in general.

I follow that example -- http://puravidaapps.com/snippets.php#2parse --
Reply all
Reply to author
Forward
0 new messages