Select to view content in your preferred language

convert image to arraybuffer in qml or javscript for further base64 conversion

3620
2
Jump to solution
12-08-2020 02:11 AM
rsharma
Frequent Contributor

Hi,

In my last post i was not able to send picture , now i can send an image to my private server with hardcode base64 data,.

But i don't know how to convert an image(i have only url of that image) to base64 string, so that i can send it through xmlhttprequest, 

The above is possible in html with javascript, but how to do it in qt quick javascript.

https://www.codegrepper.com/code-examples/cpp/convert+image+to+base64+javascript

 

I got this link below for qt but want to do it through js.

https://felgo.com/developers/forums/t/upload-jpeg-to-server-created-from-camera

Exactly i m doing the same like selecting pictures from group send an array of picture to my private server.

 

0 Kudos
1 Solution

Accepted Solutions
StephenQuan4
Emerging Contributor

Hi @rsharma,

If you are using AppStudio, then, you can do this in QML using NetworkRequest and setting the responseType to "base64". Alternatively, if the uri is to a local file, you can use the File and BinaryData objects together.

 

If you are not using AppStudio, then, but are using C++, then, you can use the QNetworkAccessManager to download your uri content. The resultant QByteArray and be converted to base64 using QByteArray::toBase64. (See https://doc.qt.io/qt-5/qbytearray.html#toBase64 )

Let me know if you need further information on either of these two strategies.

 

Stephen

View solution in original post

0 Kudos
2 Replies
rsharma
Frequent Contributor

Hi

Please anyone ellaborate ME HOW TO CONVERT IMAGE TO BINARY or ARRAYBUFFER, SO THAT FURTHER I CAN CONVERT IT INTO BASE64

0 Kudos
StephenQuan4
Emerging Contributor

Hi @rsharma,

If you are using AppStudio, then, you can do this in QML using NetworkRequest and setting the responseType to "base64". Alternatively, if the uri is to a local file, you can use the File and BinaryData objects together.

 

If you are not using AppStudio, then, but are using C++, then, you can use the QNetworkAccessManager to download your uri content. The resultant QByteArray and be converted to base64 using QByteArray::toBase64. (See https://doc.qt.io/qt-5/qbytearray.html#toBase64 )

Let me know if you need further information on either of these two strategies.

 

Stephen

0 Kudos