Android Question Blob and Http - Solved

nibbo

Active Member
Licensed User
Longtime User
Hi All

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
 

nibbo

Active Member
Licensed User
Longtime User
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.
 
Upvote 0

nibbo

Active Member
Licensed User
Longtime User
Benefits: It's just a string which is easy to handle on any platform.

Did try that but the requests were rejected as 'potentially dangerous' by the webservice.

B4X:
Dim s64 As String = BytesToString(b,0,b.Length,"UTF8")

A potentially dangerous Request.Form value was detected from the client
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
BytesToString(b,0,b.Length,"UTF8")
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.
getting 'potentially dangerous request' errors back from the service
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).
 
Upvote 0

nibbo

Active Member
Licensed User
Longtime User
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
 
Upvote 0

hatzisn

Expert
Licensed User
Longtime User
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))

Edit-
Sorry, I did not read the last message...
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…