I have an app that collects signatures and stores them in an SQLLite database as a BLOD datatype.
When the app has a data connection I want to send the BLOB data to a webservice using Http.
I tried converting it using BytesToString but keep getting 'potentially dangerous request' errors back from the service. I am guessing the generated string contains markup which is causing the rejection.
What is the best way to send BLOB / Byte data to a webservice using HTTPUtils?
Thanks DonManfred will have a look at this option.
May even be better/simpler to use file store to hold the signature as an image instead of a database BLOB.
If b contains the bytes of your image (your BLOB data), then you can't just turn that into a string via BytesToString. BytesToString assumes you are feeding it byte array that was created from a string. You need to look at StringUtil's EncodeBase64 (https://www.b4x.com/android/help/stringutils.html#stringutils_encodebase64) for encoding any type of byte array to a Base64 encoded string.
What service? Something you control? A third party service? Where is the API documentation for what you are trying to do? Right now you have not even told us what the service expects from you (right now we're guessing Base64 encoded data).
Hi Oliver, thanks for taking the time to offer suggestions.
b is a byte array, the webservice is ours but the request was being rejected before it gets to our code as the string generated looks 'dangerous'.
We could have turned validation off to allow it through but who knows what that would open us up to.
We have it working now using the file list in a httpjob.PostMultiPart as suggested by DonManfred in post 2.
Thanks
A good option and possibly an answer to your question would be to UrlEncode it before you send it. That was the answer to my problems (of course I did not EncodeBase64):
Code:
B4X:
'Send UrlEncode(EncodeBase64(BLOB))
Dim sU As StringUtils
Dim b() As Byte
'b = Get Blob
Dim sUrlEnc64 As String
sUrlEnc64 = sU.EncodeUrl(sU.EncodeBase64(b))