Welcome, Guest
Please Login or Register.    Lost Password?

How do you save a downloaded picture?
(1 viewing) (1) Guest
Go to bottomPage: 12
TOPIC: How do you save a downloaded picture?
#21176
How do you save a downloaded picture? 4 Months, 4 Weeks ago  
I go to this website that has lots of pictures. I get the code, clean the code, find the url for a picture I want. I do:

url = "blah/blah/blah.jpg"
Rainlendar_DownloadElement(url, Savage_Movie_OnDownloadElement, "movie.picture." ..value, skin, window)


So now it shows up in my window, but it is only there temporarily. If I turn my page and set a new picture to the same element, the old one is gone and I have to download it all over again when I switch the page back. So, I want to save the picture to a new file in a different folder. But how do I do this?

I'm thinking of using os.rename but where is the picture I just downloaded saved to? I can't find it in my temp folders anywhere. Does it even bother to save at all? How do I find the file to rename?
SereneSavage
Junior Boarder
Posts: 28
graphgraph
User Offline Click here to see the profile of this user
Gender: Female Location: Canada
The administrator has disabled public write access.
 
#21182
Re: How do you save a downloaded picture? 4 Months, 3 Weeks ago  
The file is not stored to disk but it's just kept in memory. You could try to use Rainlendar_Download() instead and save the returned value to a file. It is supposed to be used with text files but it should work with binaries too. Unless there is some text conversion going on somewhere...
Rainy
Moderator
Posts: 5991
graph
User Offline Click here to see the profile of this user
The administrator has disabled public write access.
 
#21183
Re:How do you save a downloaded picture? 4 Months, 3 Weeks ago  
I've tried that with various commands, but I havent gotten it to work yet. Which download manager does Rainlendar use? In my google searches I've seen "socket", "curl", and J-something. Perhaps I can narrow my search.
SereneSavage
Junior Boarder
Posts: 28
graphgraph
User Offline Click here to see the profile of this user
Gender: Female Location: Canada
The administrator has disabled public write access.
 
#21186
Re:How do you save a downloaded picture? 4 Months, 3 Weeks ago  
The network library is Curl but that doesn't matter much since it's not visible to the lua scripts.
Rainy
Moderator
Posts: 5991
graph
User Offline Click here to see the profile of this user
The administrator has disabled public write access.
 
#21222
Re:How do you save a downloaded picture? 4 Months, 1 Week ago  
Rainlendar_Download() does not work for pictures.
I do:
Code:

Rainlendar_Download(url, Savage_Test_Callback, userData)
function Savage_Test_Callback(result, data, userData)
  text = result..","..data..","..userData
  Rainlendar_SetItemValue(window, "Movie.text", "text", text) 
end


I get back: 200, , (empty blank space)
I tried researching the curl site curl.haxx.se/libcurl/c/libcurl-tutorial.html
It says "When the transfer is complete, the function returns a return code that informs you if it succeeded in its mission or not."
So yes, its returning something else when it does not find text.

I can't use Rainlendar_DownloadElement() because the picture translator kicks in.

I tried using libcurl directly, I did:
Code:

local curl = require "libcurl"  
local c = curl.new() 
function GET(url)
    c:setopt(curl.OPT_URL, url)
    local t = {} -- this will collect resulting chunks
    c:setopt(curl.OPT_WRITEFUNCTION, function (param, buf)
        table.insert(t, buf) -- store a chunk of data received
        return #buf
    end)
    c:setopt(curl.OPT_PROGRESSFUNCTION, function(param, dltotal, dlnow)
        print('%', url, dltotal, dlnow) -- do your fancy reporting here
    end)
    c:setopt(curl.OPT_NOPROGRESS, false) -- use this to activate progress
    assert(c:perform())
    return table.concat(t) -- return the whole data as a string
end
local s = GET "http://www.imdb.com/find?q=Entourage&s=all"
    Rainlendar_SetItemValue(window, "Movie.text", "text", s)
end


but all that gave me was an error in the log: "The specified procedure could not be found." It's not finding libcurl even though the log shows me the correct path and I can see the file sitting right there in Rainlendar. The curl website said that may happen for users of Windows on first use though.

I even tried popen
Code:

local t = assert(io.popen(os.Execute("http://www.imdb.com/find?q=Entourage&s=all"), "r"))
local q = t:read('*all')


but that kept returning blank data. I dont think it could execute curl either.

I also tried capturing stdout but all I could get was "".

Now from all my reading I understand that different operating systems save files differently to disk, so I know it won't be easy, but curl says that its mainly for file transfers so I'm wondering, could there be another command besides 1)Download and 2)DownloadElement, something for ftp?

The only thing stopping me right now is that I dont know what the raw data is called, otherwise I would just do io.write(name of raw data).

I'm willing to keep researching, but I don't know which direction to go. Anyone have any suggestions?
SereneSavage
Junior Boarder
Posts: 28
graphgraph
User Offline Click here to see the profile of this user
Gender: Female Location: Canada
Last Edit: 2014/06/12 22:34 By SereneSavage.
The administrator has disabled public write access.
 
#21239
Re:How do you save a downloaded picture? 4 Months, 1 Week ago  
I don't think it's possible to download binary files with Rainlendar_Download() as it converts the data to text so it gets cut as soon as there is a zero value. Rainlendar does not have libcurl bindings for lua so you can't use it either. What you could try is to use some 3rd party tool (e.g. curl or wget) to download the files to a folder.
Rainy
Moderator
Posts: 5991
graph
User Offline Click here to see the profile of this user
The administrator has disabled public write access.
 
Go to topPage: 12
get the latest posts directly to your desktop