Uploading data to Tumblr API
-
Hi,
I've been at this issue for a while and just cannot solve the issue. Using the HTTP POST Method, I wish to send images or audio files to Tumblr. I always seem to get 403 - Bad Request issue when doing this. Sending text is no issue.
Code below is what I'm using:
@void Control::uploadPhoto(QString stringy)
{
qDebug() << stringy;
QFile file("/home/user/MyDocs/Music/CuteTunes/Deluge.mp3");
file.open(QIODevice::ReadOnly);
QByteArray songArray;
songArray = file.readAll();
QUrl url1;
url1.addEncodedQueryItem("email", "");
url1.addEncodedQueryItem("password", "*");
url1.addEncodedQueryItem("type", "audio");
url1.addEncodedQueryItem("data", songArray);
arrayPost = url1.encodedQuery();
QNetworkRequest request;
request.setUrl(QUrl("http://www.tumblr.com/api/write"));
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
reply3 = manager.post(request, songArray);
connect(reply3, SIGNAL(metaDataChanged()), this, SLOT(errorCheck()));
}@Any help with this will be greatly appreciated. I have spent a very long time attempting to solve this issue.--
Thanks in advance,
Alex
-
Did you check the output of url1.encodedQuery() ?
-
It appears to be fine. Everything seems ok before the data is sent.
Thanks for the help.
-
I'm not 100% sure, but as far as I remember, QNetworkRequest does not support file upload out of the box. You will have to prepare the data (wrapping into MIME headers etc.) yourself.