signature.png into binary data

Gearcam

Active Member
Licensed User
Longtime User
This demo to save a signature as signature.png works great but i need to also upload the binary data from the signature into my sql server

I dont want to upload the actual image just the binary representation of the signature.

Any help ?

Steve
 
Maybe nut it has to work with an existing SQL that has pc programs that read it so it has to be compatible.

But if you can help me I will give it a go !

Steve
 
Upvote 0
Hi erel is there an exampl of how to do this its getting complicated.

In Visual studio 2008 this is the code that works

'if there is a signature then update the blob field
If Exists(const_signaturejpg) Then
'Read the binary file from disk
Dim fs As FileStream = New System.IO.FileStream(const_signaturejpg, FileMode.OpenOrCreate, FileAccess.Read)
Dim rawsignatureData() As Byte = New Byte(CInt(fs.Length)) {}
fs.Read(rawsignatureData, 0, rawsignatureData.Length)
fs.Close()

'this just adds the row
row!ECOLsignature = rawsignatureData

End If


Can this be converted ?

Steve
 
Last edited:
Upvote 0
Thanks Erel

I think i have this part working here is the code

Dim in As InputStream
in = File.OpenInput(File.DirRootExternal, "sign.png")
Log("in "&in)
Dim out As OutputStream
out.InitializeToBytesArray(1)
Log("out "&out)
File.Copy2(in, out)
Dim data() As Byte
data = out.ToBytesArray
out.Close
in.Close
out.Flush
Dim ff As Int
ff=data.Length
Log(ff)

Dim xx As String
Dim bt As ByteConverter
xx=bt.CharsFromBytes(data)
Log(xx)

job2.Initialize("Job2", Me)
job2.PostString(ServerUrl, "Insert INTO test ([ECOLsignature]) VALUES ('" & xx & "' )")



Ok i have added the ByteConverter part to see whats in the string to make sure its not blank

Which it is not so i think it works.

this is the log (i have shortend the hex at ETC ETC ....)
System.Data.SqlClient.SqlException: Implicit conversion from data type varchar to varbinary(max) is not allowed. Use the CONVERT function to run this query.

at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)

at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)

at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)

at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)

at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()

at System.Data.SqlClient.SqlDataReader.get_MetaData()

at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)

at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)

at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)

at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)

at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)

at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior)

at ASP.test_aspx.Page_Load(Object sender, EventArgs ec) in e:\web\demitaservi\htdocs\test.aspx:line 26
Error: Internal Server Error


Now what i need to do is change the xx in the post string to data
but it will not compile
like this
job2.PostString(ServerUrl, "Insert INTO test ([ECOLsignature]) VALUES ('" & data & "' )")

this is the error

job2.PostString(ServerUrl, \
javac 1.6.0_26
\android\datainput.java:487: cannot find symbol
symbol : method NumberToString(byte[])
location: class anywheresoftware.b4a.BA
_job2._poststring(_serverurl,"Insert INTO test ([ECOLsignature]) VALUES ('"+BA.NumberToString(_data)+"' )");

I think it is sintax error in the post data part anybody know how to do this !!

Steve
 
Upvote 0
thanks erel for hopefully getting me on the right track

is there a mod to my code to do this ?

Or an example that will help me ?

Steve
 
Upvote 0
hi Erel

I have tried toa dd this code but no lck

Dim b64 As Base64
Dim temp As Byte
temp=b64.EncodeBtoB(data, 0, data.Length)
Log(temp)

It will not compile i get his error

Compiling generated Java code. Error
B4A line: 222
temp=b64.EncodeBtoB(data, 0, data.Length)
javac 1.6.0_26
src\xxx\android\datainput.java:465: inconvertible types
found : byte[]
required: byte
_temp = (byte)(_b64.EncodeBtoB(_data,(int)(0),_data.length));
^
1 error
 
Upvote 0
Erel

I have changed that this is my code now

Dim ff As Int
Dim datastring As String
datastring=""
ff=data.Length
Log(ff)

Dim b64 As Base64
Dim temp() As Byte
temp=b64.EncodeBtoB(data, 0, data.Length)

datastring=""
ff=temp.Length
Log(ff)
For ff=0 To ff-1
datastring=datastring & temp(ff)

Next
Log(datastring)

'Return data
Log("Bin OK")

job2.Initialize("Job2", Me)
job2.PostString(ServerUrl, "Insert INTO test ([ECOLsignature]) VALUES (" & datastring & ")"


I get the following log and error in the poststring line

in (BufferedInputStream) java.io.BufferedInputStream@40e5c130
out (ByteArrayOutputStream)
11015
14688
475710647526565818........................................
Bin OK
Job 1
Error occurred. Query=Insert INTO test ([ECOLsignature]) VALUES (475710647526565818310790748210365666581656565816566656568475011966686565696665816966658169666581696665816966658169666581696665816966658169666581696665816966658169666581696665816966658169666581696665816966658169666581696665816966658169666581724750119666865816966658169666581696665816966658169666581696665816966658169666581696665816966658169666581696665816966658169666581696665816966658169666581696665816966658169666581696665817247119656582676572103651016568658373656510469666512069664756816572119656565818566658169666581696565656565656565656565696765119817066103997367811117647568165116826565651036968651197369651198570666581656565705765817368656581826682731047785697169497010466121741207068756610797697373487512011982868348102651077750741211031031077570104998971821111087410599111758311148788489517968107548148827082107100738385112848670868786491049087109781079087901109771108113995182491001101005210188113681047387711045210574105112758410874878710853105901091137510611275871091125410511211311475122116768750116551055311711576681207788711205610674121116768449788887495710690501177210552438410853117102111541011141205611880485710298514380110544756816572119696565119696665816966658169666581656565656565656569676511981706610399736781111764756816511682696565103696766658168666599706665816565817451656569676512069696683691206610474668581100104998277105771116973706975821119872666783771228511865868911076826710489107787969108568299897182111109741211031127510685507812210353791077869828590728369108758549828686108100898786112106907186109905010411297110784810088905110172108541031117969104899772105731097510711279851089097881097410997111113791071129797110113751091131151147948116989751117761095411911580691209998721217711075481168085491009888507811097521178010753101981105479110113561188048571029851438011054475711165686577666565738265120696580119684347105105105105103651111111111116575757575656710510510510365111111111111657575757565671051051051036511111111111165757575756567105105105103651111111111116575757575656710510510510365111111111111657575757565671051051051036511111111111165757575756567105105105103651111111111116575757575656710510510510365111111111111657575757565671051051051036511111111111165757575756567105105105103651111111111116575757575656710510510510365111111111111657575757565671051051051036511111111111165757575756567105105105103651111111111116575757575656710510510510365111111111111657575757565671051051051036511111111111165757575756567105105105103651111111111116575757575656710510510510365111111111111657575757565671051051051036511111111111165757575756567105105105103651111111111116575757575656710510510510365111111111111657575757565671051051051036511111111111165757575756567105105105103651111111111116575757575656710510510510365111111111111657575757565671051051051036511111111111165757575756567105105105103651111111111116575757575656710510510510365111111111111657575757565671051051051036511111111111165757575756567105105105103651111111111116575757575656710510510510365111111111111657575757565671051051051036511111111111165757575756567105105105103651111111111116575757575656710510510510365111111111111657575757565671051051051036511111111111165757575756567105105105103651111111111116575757575656710510510510365111111111111657575757565671051051051036511111111111165757575756567105105105103651111111111116575757575656710510510510365111111111111657575757565671051051051036511111111111165757575756567105105105103651111111111116575757575656710510510510365111111111111657575757565671051051051036511111111111165757575756567105105105103651111111111116575757575656710510510510365111111111111657575757565671051051051036511111111111165757575756567105105105103651111111111116575757575656710510510510365111111111111657575757565671051051051036511111111111165757575756567105105105103651111111111116575757575656710510510510365111111111111657575757565671051051051036511111111111165757575756567105105105103651111111111116575757575656710510510510365111111111111657575757565671051051051036511111111111165757575756
Error: Internal Server Error
** Activity (datainput) Pause, UserClosed = false **



I have also tried this but it does not compile
job2.PostString(ServerUrl, "Insert INTO test ([ECOLsignature]) VALUES ('" & temp() & "')")

Any idea ??

Steve
 
Last edited:
Upvote 0
Back
Top