[Gambas-user] Using a socket to download an image. Please Help ^_^

Doriano Blengino doriano.blengino at ...1909...
Sun Nov 30 11:39:37 CET 2008


Robert Moss ha scritto:
> I am trying to get an image (or any binary data) downloaded from a website
> and into a jpg file. I expect I will need to use the Byte[] datatype, but I
> absolutely can NOT use Callbacks when the data comes in this time.
>
> ...
>
> DO UNTIL(EOF(#Sock))
>     READ #Sock, sBuf, Lof(Sock)
>     sTotal &= sBuf
> LOOP
>
> CLOSE #Sock
>
>
> p1 = InStr(sTotal, "\r\n\r\n")
>
> ImgData = Mid(sTotal, p1)
>
> OPEN "localimg.jpg" FOR OUTPUT CREATE AS #myFile
> WRITE #myFile, ImgData, Len(ImgData)
> CLOSE #myFile
>   
I think there is a problem with InStr(...,"\r\n\r\n").
By taking mid$(...,p1), you retain the two CRLFs, which are not good at 
the beginning of a jpeg file.
You should get rid of the first 4 characters. May be there are still 
other problems, but this is one for sure.

Regards,

-- 
Doriano Blengino

"Listen twice before you speak.
This is why we have two ears, but only one mouth."





More information about the User mailing list