Problem reading and writing blobs

billmoultrie

Member
Licensed User
Longtime User
I want to write a .png file to mysql on a server through php. To test this I wrote the following routines which should read a file in, convert it then, display it. But I get an error, 'error loading bitmap', so I must be corrupting the data, but I can not see where. can anybody help.
B4X:
Sub Base64Out
   ' data to server
   Dim In As InputStream 
   Dim Out As OutputStream            
   Dim strPhotoSnapName As String
   Dim su As StringUtils
   Dim Buffer() As Byte            
   
      strPhotoSnapName = "smiley.png"
      In = File.OpenInput(File.DirRootExternal, strPhotoSnapName)  
      Out.InitializeToBytesArray(64000)            
      File.Copy2(In, Out)             
      Buffer = Out.ToBytesArray                    
      str64Pic = su.EncodeBase64(Buffer)     
      Log("str64Pic " & str64Pic)
      Out.Close
   'str64Pic would now be written to the server
End Sub
Sub Base64In
   ' data from server
   
   Dim In  As InputStream 
    Dim su As StringUtils 
    Dim out As OutputStream   
   Dim b() As Byte
   Dim bmp As Bitmap
   
   b =su.DecodeBase64(str64Pic)
   In.InitializeFromBytesArray(b,0,b.Length)
   
   out = File.OpenOutput(File.DirRootExternal,"New.png",False)   
    File.Copy2(In,out)        
   out.close  
   
   bmp.Initialize2(In)
   In.Close
   
   ImageView1.Bitmap = bmp

   
End Sub
 

oscar cabrales

Member
Licensed User
Longtime User
solution

I want to write a .png file to mysql on a server through php. To test this I wrote the following routines which should read a file in, convert it then, display it. But I get an error, 'error loading bitmap', so I must be corrupting the data, but I can not see where. can anybody help.
B4X:
Sub Base64Out
   ' data to server
   Dim In As InputStream 
   Dim Out As OutputStream            
   Dim strPhotoSnapName As String
   Dim su As StringUtils
   Dim Buffer() As Byte            
   
      strPhotoSnapName = "smiley.png"
      In = File.OpenInput(File.DirRootExternal, strPhotoSnapName)  
      Out.InitializeToBytesArray(64000)            
      File.Copy2(In, Out)             
      Buffer = Out.ToBytesArray                    
      str64Pic = su.EncodeBase64(Buffer)     
      Log("str64Pic " & str64Pic)
      Out.Close
   'str64Pic would now be written to the server
End Sub
Sub Base64In
   ' data from server
   
   Dim In  As InputStream 
    Dim su As StringUtils 
    Dim out As OutputStream   
   Dim b() As Byte
   Dim bmp As Bitmap
   
   b =su.DecodeBase64(str64Pic)
   In.InitializeFromBytesArray(b,0,b.Length)
   
   out = File.OpenOutput(File.DirRootExternal,"New.png",False)   
    File.Copy2(In,out)        
   out.close  
   
   bmp.Initialize2(In)
   In.Close
   
   ImageView1.Bitmap = bmp

   
End Sub

first initialize and later save the photo with this order and will work to the perfection:sign0098:
bmp.Initialize2(In)
out = File.OpenOutput(File.DirRootExternal,"New.png",False)
File.Copy2(In,out)
out.close
In.Close

ImageView1.Bitmap = bmp
 
Upvote 0
Top