Help: Downloading images

Discuss using and improving Lua and the Lua Player specific to the PSP.

Moderators: Shine, Insert_witty_name

Post Reply
youresam
Posts: 87
Joined: Sun Nov 06, 2005 1:43 am

Help: Downloading images

Post by youresam »

Can anyone help me out with downloading images from the Wlan? I saw the HTTPD code and it looks a bit complicated to SEND, but to recieve it could require some more advanced coding..

If anyone has/can do this, please tell.
Thanks.
swordman
Posts: 27
Joined: Tue Dec 27, 2005 9:04 pm

Post by swordman »

Hi, if you want to retive a file from the net, you need to use the HTTP protocol (or the FTP)
Simply send to the server a string like the following:
GET <path&filename> HTTP/1.1\r\n\r\n
Then wait on line end recive the data.
NOTE: I think that on PSP are needed more then
socket:recive() to obtain alla the data.
youresam
Posts: 87
Joined: Sun Nov 06, 2005 1:43 am

Post by youresam »

Well, I already know how to retrieve a file, but Im saying how to build it into a PNG file. I have made a program that copies all the lines from a PNG and pastes it into a new PNG, but the PNG isnt working even though if I open it in notepad, it had the same characters. I need to download a PNG and save it.
ShUr1k3n
Posts: 42
Joined: Sun Oct 16, 2005 9:04 pm

binary mode

Post by ShUr1k3n »

U must READ and WRITE the file in Binary Mode...

If u copy the characters the file will not be the same... Because some characters are not displayed...ETC...

In VB i use: Open "filename.extension" For Binary As #1

well... Google for it and u will find a lot of Stuff...


I hope that helps...
youresam
Posts: 87
Joined: Sun Nov 06, 2005 1:43 am

Post by youresam »

Thanks a lot!
I found the lua.org booklet thing, and it said that you can inclue an optional 'b' for binary mode. Testing right now, will post results...

EDIT
Nope. Doesnt work. Same results when I make it read + write binary, read binary, or just write binary. Heres my code:

Code: Select all

loadtable = ""
function load&#40;&#41;
	file = io.open&#40;"2.png", "rb"&#41;
	if file then
		for line in file&#58;lines&#40;&#41; do
		loadtable = loadtable..line
		end
		file&#58;close&#40;&#41;
	end
end

function save&#40;&#41;
	file = io.open&#40;"3.png", "wb"&#41;
	if file then
		file&#58;write&#40;loadtable&#41;
		file&#58;close&#40;&#41;
	end
end

load&#40;&#41;
save&#40;&#41;
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Post by Shine »

lines() translates newline characters, try read the whole file with read("a").
youresam
Posts: 87
Joined: Sun Nov 06, 2005 1:43 am

Post by youresam »

Ok...
So, how would I do that? I havent experimented with that abtribute yet... I mean, how would I read it or write it if I cant use variables...

Some sample code would be appreciated.

(P.S., shine, have you tried out my LUA OS yet?)
Slopey
Posts: 24
Joined: Sun Jul 31, 2005 8:13 pm

Post by Slopey »

use

local data = file:read("*a")

it'll load the entire file in binary into the data variable.

There's more info at http://www.lua.org/pil/21.2.2.html on the lua site proper.
Post Reply