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

2008-12-10 Thread Lars Hoeger
richard terry schrieb:
 On Mon, 1 Dec 2008 06:50:06 am Robert Moss wrote:

 Robert this may not be much help to you and I'm not sure how related to your 
 problem it is,  but just on the off chance. I struggled with saving a picture 
 and retrieving from a postgres field. 

 The code I included worked really well for a long time, but in the last 
 couple 
 of upgrades though it saves the file ok, it retreives a corrupt image. and I 
 get a libpng error (sob sob) and I havn't had time or inclination to re-look 
 at it.

 Please if/when you figure it out can I have a few pointers.

 Regards

 Richard



   
 The ImgData stops writing when it comes to a byte with value H00 (I
 believe) although I'm pretty sure it doesn't matter how I write the stream,
 once it's read as a String, it becomes terminated by any NULL char. So my
 question is this: How do I read the data from the Socket in binary, write
 it to a stream file in binary, but STILL I MUST be able to split the data
 based on the 2 CRLF's

 On Sun, Nov 30, 2008 at 11:48 AM, Robert Moss 
 
 [EMAIL PROTECTED]wrote:
   
 Sorry that's not it, I mis-copied the line, in the actual code it does
 Mid(sData, p1 + 4)

 On Sun, Nov 30, 2008 at 2:39 AM, Doriano Blengino 

 [EMAIL PROTECTED] wrote:
   
 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.


 
 - This SF.Net email is sponsored by the Moblin Your Move Developer's
 challenge
 Build the coolest Linux based applications with Moblin SDK  win great
 prizes
 Grand prize is a trip for two to an Open Source event anywhere in the
 world
 http://moblin-contest.org/redirect.php?banner_id=100url=/
 ___
 Gambas-user mailing list
 Gambas-user@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/gambas-user
 
 -
 This SF.Net email is sponsored by the Moblin Your Move Developer's
 challenge Build the coolest Linux based applications with Moblin SDK  win
 great prizes Grand prize is a trip for two to an Open Source event anywhere
 in the world http://moblin-contest.org/redirect.php?banner_id=100url=/
 ___
 Gambas-user mailing list
 Gambas-user@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/gambas-user
 


   
 

 -
 This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
 Build the coolest Linux based applications with Moblin SDK  win great prizes
 Grand prize is a trip for two to an Open Source event anywhere in the world
 http://moblin-contest.org/redirect.php?banner_id=100url=/
 

 ___
 Gambas-user mailing list
 Gambas-user@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/gambas-user
Hi Richard,

could you comment on your code? I understand the section ifbuffer ... 
not.

Thank you very much

Lars

--
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you.  Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


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

2008-12-01 Thread Benoit Minisini
On dimanche 30 novembre 2008, Robert Moss wrote:
 The ImgData stops writing when it comes to a byte with value H00 (I
 believe) although I'm pretty sure it doesn't matter how I write the stream,
 once it's read as a String, it becomes terminated by any NULL char. So my
 question is this: How do I read the data from the Socket in binary, write
 it to a stream file in binary, but STILL I MUST be able to split the data
 based on the 2 CRLF's


Strange, it should work. I mean: zero bytes in a string does not matter, as 
soon as the string is not passed through some methods of components written 
in C/C++, because there strings sometimes needs to be zero terminated.

You can read/write arrays from streams if you need: they all have a Read 
method and a Write method for that.

Anyway can you send me your full source code?

-- 
Benoit Minisini

-
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK  win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100url=/
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


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

2008-11-30 Thread Robert Moss
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.

Here is my example:

DIM RequestString as string
DIM sTotal as string
DIM sBuf as string

Sock.Connect(host,80)
RequestString = MakeGetRequest(/imagesurl.jpg) 'returns a string like
HTTP/1.1 GET /page... \r\n its all correct
WRITE #Sock, RequestString, Len(RequestString)

'Code to wait for connection, etc is removed for brevity

DO UNTIL(EOF(#Sock))
READ #Sock, sBuf, Lof(Sock)
sTotal = sBuf
LOOP

CLOSE #Sock

And after I separate the Content of the reply and dump it to a file, its not
readable, I presume this is because I am trying to write binary data as a
string

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


Keep in mind, the http request looks something like

HTTP/1.0 200 OK
Header-X: Value1
Content-Type: image/jpeg

AFdka;h3ijaf #RVA  'Image Data

So I need a way to correctly write the binary data to a file without also
including the content headers


Thank you
-
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK  win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100url=/
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


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

2008-11-30 Thread Robert Moss
Sorry that's not it, I mis-copied the line, in the actual code it does
Mid(sData, p1 + 4)

On Sun, Nov 30, 2008 at 2:39 AM, Doriano Blengino 
[EMAIL PROTECTED] wrote:

 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.


 -
 This SF.Net email is sponsored by the Moblin Your Move Developer's
 challenge
 Build the coolest Linux based applications with Moblin SDK  win great
 prizes
 Grand prize is a trip for two to an Open Source event anywhere in the world
 http://moblin-contest.org/redirect.php?banner_id=100url=/
 ___
 Gambas-user mailing list
 Gambas-user@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/gambas-user

-
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK  win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100url=/
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


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

2008-11-30 Thread Robert Moss
The ImgData stops writing when it comes to a byte with value H00 (I
believe) although I'm pretty sure it doesn't matter how I write the stream,
once it's read as a String, it becomes terminated by any NULL char. So my
question is this: How do I read the data from the Socket in binary, write it
to a stream file in binary, but STILL I MUST be able to split the data based
on the 2 CRLF's

On Sun, Nov 30, 2008 at 11:48 AM, Robert Moss [EMAIL PROTECTED]wrote:

 Sorry that's not it, I mis-copied the line, in the actual code it does
 Mid(sData, p1 + 4)

 On Sun, Nov 30, 2008 at 2:39 AM, Doriano Blengino 
 [EMAIL PROTECTED] wrote:

 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.


 -
 This SF.Net email is sponsored by the Moblin Your Move Developer's
 challenge
 Build the coolest Linux based applications with Moblin SDK  win great
 prizes
 Grand prize is a trip for two to an Open Source event anywhere in the
 world
 http://moblin-contest.org/redirect.php?banner_id=100url=/
 ___
 Gambas-user mailing list
 Gambas-user@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/gambas-user



-
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK  win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100url=/
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


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

2008-11-30 Thread richard terry
On Mon, 1 Dec 2008 06:50:06 am Robert Moss wrote:

Robert this may not be much help to you and I'm not sure how related to your 
problem it is,  but just on the off chance. I struggled with saving a picture 
and retrieving from a postgres field. 

The code I included worked really well for a long time, but in the last couple 
of upgrades though it saves the file ok, it retreives a corrupt image. and I 
get a libpng error (sob sob) and I havn't had time or inclination to re-look 
at it.

Please if/when you figure it out can I have a few pointers.

Regards

Richard



 The ImgData stops writing when it comes to a byte with value H00 (I
 believe) although I'm pretty sure it doesn't matter how I write the stream,
 once it's read as a String, it becomes terminated by any NULL char. So my
 question is this: How do I read the data from the Socket in binary, write
 it to a stream file in binary, but STILL I MUST be able to split the data
 based on the 2 CRLF's

 On Sun, Nov 30, 2008 at 11:48 AM, Robert Moss 
[EMAIL PROTECTED]wrote:
  Sorry that's not it, I mis-copied the line, in the actual code it does
  Mid(sData, p1 + 4)
 
  On Sun, Nov 30, 2008 at 2:39 AM, Doriano Blengino 
 
  [EMAIL PROTECTED] wrote:
  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.
 
 
  
 - This SF.Net email is sponsored by the Moblin Your Move Developer's
  challenge
  Build the coolest Linux based applications with Moblin SDK  win great
  prizes
  Grand prize is a trip for two to an Open Source event anywhere in the
  world
  http://moblin-contest.org/redirect.php?banner_id=100url=/
  ___
  Gambas-user mailing list
  Gambas-user@lists.sourceforge.net
  https://lists.sourceforge.net/lists/listinfo/gambas-user

 -
 This SF.Net email is sponsored by the Moblin Your Move Developer's
 challenge Build the coolest Linux based applications with Moblin SDK  win
 great prizes Grand prize is a trip for two to an Open Source event anywhere
 in the world http://moblin-contest.org/redirect.php?banner_id=100url=/
 ___
 Gambas-user mailing list
 Gambas-user@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/gambas-user


Public Function Image_Save(ImagePath As String) As Integer
'
'Saves an image file to clin_consult.images table
'return its key
'
Dim hFile As Stream
Dim buffer As Byte
Dim picText As String
Dim img As Image
Dim newPicture As Result
Dim pictureData As String
Dim scale As Float

  Open ImagePath For Input As #hFile
While Not Eof(hFile)
  Read #hFile, buffer, Lof(hFile)
  If buffer  32 Or buffer  126 Then
picText = picText    Coct(buffer)
  Else
Select buffer
  Case 92' mask  | char
picText = picText  134
  Case 39' mask ' char
picText = picText  \\'
  Default
picText = picText  Chr$(buffer)
End Select
  End If
Wend
  Close hFile
   '---
   'Start transaction, insert the piccie
   '
sql = insert into clin_consult.images(image)
sql = values(E'  picText  ')
$Result = modDBConnect.exec_query(sql)
	sql = SELECT currval( 'clin_consult.images_pk_seq') as pk
	$Result = modDBConnect.exec_query(sql)
	Return $Result!pk
End

Private Function COct(num As Integer) As String
  Dim octnumber As New Integer[]
  Dim octstring As String

  octnumber.Add(Int(num / 64))
  octnumber.Add(Int((num Mod 64) / 8))
  octnumber.Add((num Mod 64) Mod 8)
  octstring = octnumber[0]  octnumber[1]  octnumber[2]
  Return octstring
End-
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with