Save remote image to disk
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Save remote image to disk
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!
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
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:"
Hint: pay close attention to the section on "file:" and "binfile:"
Re: Save remote image to disk
I've tried something like this:
But most of the times, the file .jpg is corrupted or shows weird stuff (like wrong pixels)...

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
I'll do thatmagice wrote: Hint: pay close attention to the section on "file:" and "binfile:"

Re: Save remote image to disk
<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
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
Nice! Works! Almost got it by myself but needed the url() function...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

Thanks to all! Now I can move on, have a nice one!!!
Re: Save remote image to disk
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.AlbertoP wrote: Nice! Works! Almost got it by myself but needed the url() function...![]()