[Development] XMLHttpRequest.send() with arbitrary data

Alberto Mardegan mardy at users.sourceforge.net
Thu Jun 22 23:20:39 CEST 2017


Hi all,
   my understanding looking at the implementation of the 
XMLHttpRequest.send() method in QtDeclarative [1] is that the
said method only accepts UTF-8 data as parameter.

Now, I would like to be able to send arbitrary data (in order to, for 
example, upload a JPEG image to flickr) and I believe that the 
limitation above is preventing me from doing so: my QByteArray (which 
I'm actually preparing from the C++ side and then converting into a 
QString with QString::fromUtf8()) is not being transmitted properly. No 
surprise here, as I understand that the QString::fromUtf8() method will 
stop as soon as a zero byte is found.

But than, what is the way forward? I see that javascript has some more 
types such as Blob and ArrayBufferView, which at least judging by the 
name could be suitable types for transporting binary data. I see that 
there is a newArrayBuffer() method in QJSEngine's private class; would 
exporting that to the client help in any way?

Or should the implementation of XMLHttpRequest.send() try to first 
convert its parameter to a QByteArray (via QJSValue::fromScriptValue()) 
and only fallback to QString if that fails?

Ciao,
   Alberto


[1]: 
http://code.qt.io/cgit/qt/qtdeclarative.git/tree/src/qml/qml/qqmlxmlhttprequest.cpp?h=dev#n1814



More information about the Development mailing list