nibbo Active Member Licensed User Longtime User Nov 7, 2018 #1 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
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
DonManfred Expert Licensed User Longtime User Nov 7, 2018 #2 nibbo said: using HTTPUtils? Click to expand... PostMultipart. Upvote 0
nibbo Active Member Licensed User Longtime User Nov 7, 2018 #3 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
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.
KMatle Expert Licensed User Longtime User Nov 7, 2018 #4 What I do: Convert the image(s) via byte array to a Base64 STRING and vice versa. Helper: https://www.b4x.com/android/forum/threads/b4x-bytes-to-file.70111/ Benefits: It's just a string which is easy to handle on any platform. Upvote 0
What I do: Convert the image(s) via byte array to a Base64 STRING and vice versa. Helper: https://www.b4x.com/android/forum/threads/b4x-bytes-to-file.70111/ Benefits: It's just a string which is easy to handle on any platform.
nibbo Active Member Licensed User Longtime User Nov 8, 2018 #5 KMatle said: Benefits: It's just a string which is easy to handle on any platform. Click to expand... Did try that but the requests were rejected as 'potentially dangerous' by the webservice. Code: Dim s64 As String = BytesToString(b,0,b.Length,"UTF8") A potentially dangerous Request.Form value was detected from the client Click to expand... Upvote 0
KMatle said: Benefits: It's just a string which is easy to handle on any platform. Click to expand... Did try that but the requests were rejected as 'potentially dangerous' by the webservice. Code: Dim s64 As String = BytesToString(b,0,b.Length,"UTF8") A potentially dangerous Request.Form value was detected from the client Click to expand...
OliverA Expert Licensed User Longtime User Nov 8, 2018 #6 nibbo said: BytesToString(b,0,b.Length,"UTF8") Click to expand... 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. nibbo said: getting 'potentially dangerous request' errors back from the service Click to expand... 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 said: BytesToString(b,0,b.Length,"UTF8") Click to expand... 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. nibbo said: getting 'potentially dangerous request' errors back from the service Click to expand... 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).
nibbo Active Member Licensed User Longtime User Nov 8, 2018 #7 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
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
hatzisn Expert Licensed User Longtime User Nov 8, 2018 #8 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: Code: '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: Nov 8, 2018 Upvote 0
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: Code: '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...