URL Encoding

07-25-2019 06:11 AM
New Contributor III

Hello everyone,

I need to send an image using  XMLHttpRequest 

and for that the  image data needs to be encoded, in javascript  this function FileReader.readAsDataURL() does this perfectly, but i'm not able to do so using QML.

I'm only able to read the image as binary values like this "\xFF\xD8\xFF....etc"

Could you please let me know how i can achieve this using ArcGIS Runtime Qt SDK QML.

Thanks in advance.

Tags (3)
0 Kudos
3 Replies
Esri Frequent Contributor

The Runtime API doesn't have any utilities to read images like this.

Adding AppStudio for ArcGIS‌ to see if they have any suggestions.

Occasional Contributor III

If you're using AppStudio for ArcGIS, there are several ways for working with images and uploading.

1. NetworkRequest has built in support for multipart/form-data if it detects a file upload in the request (similar to Unix curl command).

NetworkRequest {
id: networkRequest
method: "POST"
url: "https://some.end.point"

networkRequest.send( {
f: "pjson",
file: networkRequest.uploadPrefix + "myimage.png"
} )

This is the best method, because (a) your application logic is simple, (b) the file is not loaded into memory, but streamed in blocks directly from file to the internet, allow one to upload very large files, (c) you needn't worry about setting your headers correctly for a multipart/form-data upload, this is done for you automatically.

2. We have File and BinaryData object for reading a file and converting it to another format, e.g. base64 encoding

0 Kudos
New Contributor III

Hi Stephen,

Thanks for your response.

you mentioned that the NetworkRequest detects a file in the request,

Is this happens because in the body object you added a file property, if so what if the object is complex and has more properties not only file and f

and the property name not file --data instead.












Will the NetworkRequest still going to detect that a file in the request and set the headers to "multipart/form-data"

Also i tried to use Binarydata several times, but no luck till now to convert the image to (URL Encoded format).

the following is example of an image after reading its data as URL encoded format, and this allows me to send it using  XMLHttpRequest  and NetworkRequest


If you copy and paste the previous value on the browser, an image will be shown.

Could you please let me know if there is a way that allows me to convert the image data into that format.

0 Kudos