[Development] XMLHttpRequest.send() with arbitrary data

Simon Hausmann Simon.Hausmann at qt.io
Fri Jun 23 10:08:05 CEST 2017


Hi,


I think send() should be fixed to support more than just strings as parameters. For example in browsers

you can use send() with array buffers and blob objects. We don't support the latter, but the former we do

and they are also our mapping for QByteArray.


Want to give it a try? It should be a relatively straight-forward change and we have good XHR test coverage, so

it should be easy to extend the tests to cover this.


Simon

________________________________
From: Development <development-bounces+simon.hausmann=qt.io at qt-project.org> on behalf of Alberto Mardegan <mardy at users.sourceforge.net>
Sent: Thursday, June 22, 2017 11:20:39 PM
To: development at qt-project.org
Subject: [Development] XMLHttpRequest.send() with arbitrary data

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
_______________________________________________
Development mailing list
Development at qt-project.org
http://lists.qt-project.org/mailman/listinfo/development
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20170623/d017246f/attachment.html>


More information about the Development mailing list