Qt Imgur 上传失败
我有一个上传器,比如这个
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();
}
文件是 QByteArray,其中包含我想要上传的 PNG 文件内容。 上传结束时,我收到响应,但上传的图像无效(如果我保存它并尝试打开,它会写入该文件不是有效的 PNG 图像)。
我做错了什么?
I have an uploader like this
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();
}
file is QByteArray with PNG file content which i want to upload.
When uploading ends, I receive the response, but uploaded image is not valid (if i save it and trying to open, it writes that the file is not valid PNG image).
What I'm doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论