Page 1 of 1
Save remote image to disk
Posted: Thu Nov 13, 2014 2:54 pm
by AlbertoP
Hi all,
Thanks for this great forum. I'm a complete livecode beginner, and I'm having trouble finding how to save a remote image into the disk (local or samba).
I need this for a project that involves twitter and live production for media. I need to download images from tweets, save them into the disk to access them later on. I have the URL of the images, just need to download the content properly.
I guess it is a simple operation (has to be trivial!) but I can't find how to do it!
Thanks!
Re: Save remote image to disk
Posted: Thu Nov 13, 2014 4:31 pm
by magice
I think, if I am understanding you correctly, that you need to look up "url" in the LiveCode dictionary. Specifically "put your image into URL your url"
Hint: pay close attention to the section on "file:" and "binfile:"
Re: Save remote image to disk
Posted: Thu Nov 13, 2014 4:37 pm
by AlbertoP
I've tried something like this:
Code: Select all
put "./tmp/" & user_id_str & ".jpg" into profile_img_filename
open file profile_img_filename for write
put URL profile_image_url into profile_img_filename
close file profile_img_filename
But most of the times, the file .jpg is corrupted or shows weird stuff (like wrong pixels)...
magice wrote:
Hint: pay close attention to the section on "file:" and "binfile:"
I'll do that

Re: Save remote image to disk
Posted: Thu Nov 13, 2014 4:56 pm
by Klaus
<Hi Alberto,
you are mixing some different techniques and that is not healthy for the downloaded file
Do like this and use the shorter URL syntax:
...
## Only use this if you are SURE, WHAT THE CURRENT FOLDER IS!
put "./tmp/" & user_id_str & ".jpg" into profile_img_filename
## Images are binary stuff, so wen use BINFILE here!
## FILE is just for simple text files!
put URL profile_image_url into url("BINFILE:" & profile_img_filename)
...
No need to open/close that file with the URL syntax!
Best
Klaus
Re: Save remote image to disk
Posted: Thu Nov 13, 2014 5:02 pm
by AlbertoP
Klaus wrote:<Hi Alberto,
you are mixing some different techniques and that is not healthy for the downloaded file
Do like this and use the shorter URL syntax:
...
## Only use this if you are SURE, WHAT THE CURRENT FOLDER IS!
put "./tmp/" & user_id_str & ".jpg" into profile_img_filename
## Images are binary stuff, so wen use BINFILE here!
## FILE is just for simple text files!
put URL profile_image_url into url("BINFILE:" & profile_img_filename)
...
No need to open/close that file with the URL syntax!
Best
Klaus
Nice! Works! Almost got it by myself but needed the url() function...
Thanks to all! Now I can move on, have a nice one!!!
Re: Save remote image to disk
Posted: Thu Nov 13, 2014 6:17 pm
by magice
AlbertoP wrote:
Nice! Works! Almost got it by myself but needed the url() function...
Actually this is not technically a function. It reads like one, and I thought it was myself for a while. What it actually is, is the url keyword followed by the strung together url within the parenthesis operators. When you look at it that way, it is a little easier to understand what is happening.