我在这里看不到任何类似的问题,所以这就是我提出这个话题的原因。
我正在使用DropBox Core REST API制作QT C ++应用程序。我没有问题验证,我可以上传,但问题是某些类型在上传后像图像文件,视频文件和拉链一样无效,奇怪的是PDF和MP3不会失效。
[CODE - 用于上传的QT C ++代码]
// ----- Javascript
var params = new Object();
params.url = "https://api-content.dropbox.com/1/files_put/"+currentPath+"/"+baseFileName+"?access_token=" + dropboxAccessToken
params.filename = fileName;
params.basefilename = baseFileName;
params.endpoint = "dropboxUpload";
uploader.uploadDropBox(params);
// ----- CPP
QVariantMap paramsMap = params.toMap();
const QString endpoint = paramsMap.value("endpoint").toString();
const QString filename = paramsMap.value("filename").toString();
const QString basefilename = paramsMap.value("basefilename").toString();
const QString theurl = paramsMap.value("url").toString();
QHttpMultiPart *multiPart = new QHttpMultiPart();
QHttpPart filePart;
QFile *file = new QFile(filename);
file->open(QIODevice::ReadOnly);
filePart.setBodyDevice(file);
file->setParent(multiPart);
multiPart->append(filePart);
QUrl urlQuery(theurl);
QNetworkRequest request(urlQuery);
QNetworkReply *reply = networkAccessManager.post(request, multiPart);
reply->setProperty("endpoint", endpoint);
multiPart->setParent(reply);
connect (reply, SIGNAL(finished()), this, SLOT(onComplete()));
[IMAGE - 突出显示的文件很好,其余的是打开时无效的文件]
[图片 - 无法预览]
[IMAGE - PDF文件成功打开没有问题]
有什么建议吗?
答案 0 :(得分:1)
我已经解决了我的问题
QVariantMap paramsMap = params.toMap();
const QString endpoint = paramsMap.value("endpoint").toString();
const QString filename = paramsMap.value("filename").toString();
const QString basefilename = paramsMap.value("basefilename").toString();
const QString theurl = paramsMap.value("url").toString();
QHttpPart filePart;
QFile *file = new QFile(filename);
file->open(QIODevice::ReadOnly);
QUrl urlQuery(theurl);
QNetworkRequest request(urlQuery);
QNetworkReply *reply = networkAccessManager.put(request, file->readAll());
reply->setProperty("endpoint", endpoint);
connect (reply, SIGNAL(finished()), this, SLOT(onComplete()));