Save remote image to disk

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
AlbertoP
Posts: 7
Joined: Thu Nov 13, 2014 2:48 pm

Save remote image to disk

Post by AlbertoP » Thu Nov 13, 2014 2:54 pm

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!

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Re: Save remote image to disk

Post by magice » Thu Nov 13, 2014 4:31 pm

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:"

AlbertoP
Posts: 7
Joined: Thu Nov 13, 2014 2:48 pm

Re: Save remote image to disk

Post by AlbertoP » Thu Nov 13, 2014 4:37 pm

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 ;)

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Save remote image to disk

Post by Klaus » Thu Nov 13, 2014 4:56 pm

<Hi Alberto,

you are mixing some different techniques and that is not healthy for the downloaded file :D
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! 8)


Best

Klaus

AlbertoP
Posts: 7
Joined: Thu Nov 13, 2014 2:48 pm

Re: Save remote image to disk

Post by AlbertoP » Thu Nov 13, 2014 5:02 pm

Klaus wrote:<Hi Alberto,

you are mixing some different techniques and that is not healthy for the downloaded file :D
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! 8)


Best

Klaus
Nice! Works! Almost got it by myself but needed the url() function... :oops:

Thanks to all! Now I can move on, have a nice one!!!

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Re: Save remote image to disk

Post by magice » Thu Nov 13, 2014 6:17 pm

AlbertoP wrote: Nice! Works! Almost got it by myself but needed the url() function... :oops:
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.

Post Reply