我有一个这样的上传者
void uploader::upload() {
QUrl serviceUrl = QUrl("http://api.imgur.com/2/upload.json");
QByteArray postData;
postData.append("key=MY_KEY&");
postData.append("image=" + file.toBase64());
QNetworkAccessManager *networkManager = new QNetworkAccessManager(this);
connect(networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(serviceRequestFinished(QNetworkReply*)));
networkManager->post(QNetworkRequest(serviceUrl), postData);
}
void uploader::serviceRequestFinished(QNetworkReply* reply) {
qDebug() << "Done" << endl;
QString response = reply->readAll();
qDebug() << response;
QScriptValue sc;
QScriptEngine engine;
sc = engine.evaluate(response);
qDebug() << sc.property("upload").property("links").property("original").toString();
}
文件是带有我要上传的 PNG 文件内容的 QByteArray。上传结束时,我收到响应,但上传的图像无效(如果我保存并尝试打开,它会写入文件不是有效的 PNG 图像)。
我做错了什么?