Some help with Facebook + Qt FORM http

Tomaz Canabrava tcanabrava at kde.org
Wed Dec 24 16:51:00 PST 2014


People,
I'm having a hard time trying to understand how to do one simple thing:

Send an image to facebook using POST http method.

from facebook doc:


   1. Capture a photo via file upload as multipart/form-data then use the
   source parameter:

POST /v2.2/{album-id}/photos HTTP/1.1Host: graph.facebook.com

source=%7Bimage-data%7D

With Qt, I'v tried to:

QHttpMultiPart *multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType);
QHttpPart imagePart;
imagePart.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("image/png"));
imagePart.setHeader(QNetworkRequest::ContentDispositionHeader,
QVariant("form-data; name=\"source\""));
QFile *file = new QFile("/home/tcanabra/Downloads/pics/coiso.png");
file->open(QIODevice::ReadOnly);
imagePart.setBodyDevice(file);
multiPart->append(imagePart);
QUrl url("https://graph.facebook.com/v2.2/" +
QString(prefs.facebook.album_id) + "/photos?&access_token=" +
QString(prefs.facebook.access_token));
QNetworkRequest request(url);
QNetworkAccessManager manager;
QNetworkReply *reply = manager.post(request, multiPart);

The error that Facebook tells me is:

"{"error":{"message":"(#324) Requires upload
file","type":"OAuthException","code":324}}"

wich I don't really understand, manager.post() should have done the upload
of the file, no?
I'm really lost.

Tomaz
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.subsurface-divelog.org/pipermail/subsurface/attachments/20141224/7c72211a/attachment-0001.html>


More information about the subsurface mailing list