-1
Facebookに画像をアップロードしようとしていますが、常にエラー:"{"error":{"message":"(#324) Requires upload file","type":"OAuthException","code":324,"fbtrace_id":"Fsi2f\/H6ggp"}}"
が返されます。 私はQt 4.8を使用しており、私のコードで後述するようにマルチパートリクエストを設定しています。Qt C++を使用したFacebook写真のアップロードエラー
QFile file(m_fileName);
QFileInfo fileInfo(m_fileName); // to get info on the file
bool open = file.open(QIODevice::ReadOnly);
if(open){
// start the upload
QHttpMultiPart *multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType);
QHttpPart privacyPart;
privacyPart.setHeader(QNetworkRequest::ContentTypeHeader, "text/plain; charset=UTF-8");
privacyPart.setHeader(QNetworkRequest::ContentDispositionHeader, "form-data; name=\"privacy\"");
privacyPart.setBody("{\"value\":\"FRIENDS_OF_FRIENDS\"}");
QHttpPart filePart;
filePart.setHeader(QNetworkRequest::ContentTypeHeader, "image/png");
filePart.setHeader(QNetworkRequest::ContentDispositionHeader, "form-data; name=\"source\"; filename = \"" + fileInfo.fileName() + "\"");
filePart.setRawHeader("Content-Transfer-Encoding", "binary");
filePart.setBody(file.readAll());
multiPart->append(privacyPart);
multiPart->append(filePart);
QNetworkRequest request(url);
request.setRawHeader("Authorization", "OAuth " + accessToken.toUtf8());
QNetworkReply* reply = m_networkAccessManager->post(request, multiPart);
multiPart->setParent(reply); // delete multipart with reply
// connect signals
connect(reply, SIGNAL(uploadProgress(qint64,qint64)), this, SLOT(uploadProgress(qint64,qint64)));
connect(reply, SIGNAL(finished()), this, SLOT(replyFinished()));
}
else{
qDebug() << "Unable to open file" << fileName();
qDebug() << file.errorString();
}