Author |
Message |
skootles
|
Posted: Fri Jan 27, 2006 10:25 pm Post subject: Downloaded files are unviewable |
|
|
Okay, so I already made a post about this, I'm trying to make it so the user can update parts of the program by clicking buttons and yadda yadda yadda.. the files are downloaded to their computer. Ok, so I came up with this:
code: | var url : string := "http://www.microsoft.com/resources/design/images/pop_img_mob_01.jpg"
var netStream : int
var file : char
var filenum : int
netStream := Net.OpenURLConnection (url)
if netStream = 0 then
put url, " could not be located."
return
end if
open : filenum, "TestFile.jpg", put
loop
exit when eof (netStream)
get : netStream, file
put : filenum, file..
end loop |
Which does work.. except the output image is slightly larger that the test one I'm using, and I'm unable to view it. In anything. Can anyone tell me what's going wrong here? Thanks! |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Tony
|
Posted: Sat Jan 28, 2006 12:56 am Post subject: (No subject) |
|
|
you're reading it line by line as text. save your JPEG as TXT and then back, see if you get any corruption. Amplified by Net.'s tendency to loose information, you could run into fatal problems.
Two ideas:
1 -- read/write instead of get/put
2 -- validation. Run some checksum comparisons to ensure that correct content has been downloaded. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
skootles
|
Posted: Sat Jan 28, 2006 10:33 am Post subject: (No subject) |
|
|
I replaced "put" with "write" and it works great!
+ bits.
But there's just one issue.. when I try and get files that have more than one "." in them (for example, gal.water.ap.jpg), it doesn't seem to work.
code: | var url : string := "http://bb.domaindlx.com/Plixo/gal.water.ap.jpg"
var netStream : int
var file : char
var filenum : int
netStream := Net.OpenURLConnection (url)
if netStream = 0 then
put url, " could not be located."
return
end if
open : filenum, "postfile.jpg", write
loop
exit when eof (netStream)
get : netStream, file
write : filenum, file
end loop |
|
|
|
|
|
|
Tony
|
Posted: Sat Jan 28, 2006 5:17 pm Post subject: (No subject) |
|
|
well my guess would be that Turing confuses what part of a.b.c is the actual extension and might be dropping something..
for a fun experiment, upload 2 files into the same folder
a.b
a.b.c
try to download a.b.c with Turing and see if you end up with a.b or not
The thought of bits is appreciated, but notice the
|
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
md
|
Posted: Sat Jan 28, 2006 6:02 pm Post subject: (No subject) |
|
|
Try echoing what you receive to teh screen too... My experience with turing's netwrking code is nil, but unless it's handling ALL of the http protocol stuff for you there might be more you need to do. |
|
|
|
|
|
skootles
|
Posted: Sat Jan 28, 2006 11:48 pm Post subject: (No subject) |
|
|
Well, I uploaded these files:
a.b.jpg
a.jpg
b.jpg
a.b
And made it try to get "a.b.jpg", but it didn't seem to get any of those... so I tried what cornflake said:
Cornflake wrote: Try echoing what you receive to teh screen too... My experience with turing's netwrking code is nil, but unless it's handling ALL of the http protocol stuff for you there might be more you need to do.
and got this:
Strangely, when I try to get and .gif file, I get this:
So maybe it's a turing thing? Because turing doesn't support .gif files... |
|
|
|
|
|
md
|
Posted: Sun Jan 29, 2006 12:12 am Post subject: (No subject) |
|
|
As I thought, it's just connecting to the server, if you want to get pages from an HTTP server you need to speak HTTP to it. I don't know of a good resource of hand for that, but google does wonders |
|
|
|
|
|
skootles
|
Posted: Sun Jan 29, 2006 12:22 am Post subject: (No subject) |
|
|
Ahh.. this is getting increasingly complicated
I had this all nice in VB, but it had a few bugs, and I accidentally deleted the project file |
|
|
|
|
|
Sponsor Sponsor
|
|
|
md
|
Posted: Sun Jan 29, 2006 12:51 am Post subject: (No subject) |
|
|
I think if you connect to the server after it sends you some stuff you can send it a GET command (syntax unsure), which should get you another http header and the file. |
|
|
|
|
|
Tony
|
Posted: Sun Jan 29, 2006 1:38 am Post subject: (No subject) |
|
|
skootles -- I've just posted in your other Internet files thread. CompSci.ca recognizes bot connections and filters them out. You'd get errors if you try to connect to files hosted on our domain from Turing. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
md
|
Posted: Sun Jan 29, 2006 3:03 am Post subject: (No subject) |
|
|
Tony wrote: skootles -- I've just posted in your other Internet files thread. CompSci.ca recognizes bot connections and filters them out. You'd get errors if you try to connect to files hosted on our domain from Turing.
Not so! If you tell the server your user-agent is something that compsci recognizes as non-bot then it won't think so at all! It's just a matter of speaking HTTP and saying the right things. |
|
|
|
|
|
Dan
|
Posted: Sun Jan 29, 2006 4:34 am Post subject: (No subject) |
|
|
It is also about what file you are trying to play with and how many times you try to call it. Also about what chars you use in your url line and what syboles are in it. |
Computer Science Canada
Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more! |
|
|
|
|
ecliptical
|
Posted: Tue Jan 31, 2006 2:07 am Post subject: (No subject) |
|
|
I think I'm perhaps one of the more active/willing Net module people...so here's my contribution the net code you're looking for is
var requestString := "GET /" + htmlpage + " HTTP/1.1"' + char(10) + "Host: " + hostname;
var fullrequestString := requestString + char(10) + "Accept: */*'"+ char(10) + "'Connection: close" + char(10) + char(10);
You can't use the default Net.OpenURLConnection unless you modify the turing module to include "put" so you can send... otherwise use Net.OpenConnection (on port 80)
Also you might want to weed out some of the html crud you'll get so here is a very dirty and quick HTML Parser(not really more like a HTML Stripper)
code: |
var flag:boolean
exit when eof (netStream)
get : netStream, net_line
if net_line = "<" then
flag := true
elsif net_line = ">" then
flag := false
end if
if not flag and net_line not= ">" and net_line not= "<" then
put net_line ..
write : fileNo, net_line
end if
|
I've rewritten most of this code on the fly...so there might be various mistakes...I'm not sure what char(10) is but it's supposed to be carriage return...so use whatever char is carriage return (enter).
Thats all... |
|
|
|
|
|
ecliptical
|
Posted: Tue Jan 31, 2006 2:10 am Post subject: (No subject) |
|
|
also remember close your connection
code: | Net.CloseConnection (netStream) |
|
|
|
|
|
|
md
|
Posted: Tue Jan 31, 2006 12:59 pm Post subject: (No subject) |
|
|
If he's only requesting images then he doesn't need to worry about HTML tags, he does however need to know how to parse the returned header enough to extract the file.
Oh, and your tag code wouldn't work |
|
|
|
|
|
|