我想使用我的应用程序将文件上传到Box.net。我做了其他一切,我无法找到如何向box.net请求上传 文件。在开发人员网上已经提到了类似的内容来上传文件
curl https://upload.box.com/api/2.0/files/content \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-F filename=@FILE_NAME \
-F folder_id=PARENT_FOLDER_ID
我做了这么多\
O2Requestor * requestor = new O2Requestor(Core::sharedManager ()->getNetworkAccessManager (), mO2BoxNet, this);
QUrl url = QUrl("https://upload.box.com/api/2.0/files/content");
QNetworkRequest request(url);
request.setRawHeader("Authorization","462K9Ic9S*************GD");
我想知道我应该如何追加其他两个参数,即
-F filename=@FILE_NAME \
-F folder_id=PARENT_FOLDER_ID
请求以及如何在Post函数中发布请求.i.e参数。
答案 0 :(得分:1)
以下是您可以在官方Qt doc上找到here的示例的修改版本。
QHttpMultiPart *multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType);
QHttpPart textPart;
textPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"folder_id\""));
textPart.setBody("my parent folder id"); // the PARENT_FOLDER_ID
QHttpPart imagePart;
imagePart.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("image/jpeg")); // the actual content-type for your file
imagePart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"filename\""));
QFile *file = new QFile("image.jpg");
file->open(QIODevice::ReadOnly);
imagePart.setBodyDevice(file);
file->setParent(multiPart);
request.setRawHeader("Authorization","462K9Ic9S*************GD");
QNetworkReply *reply = manager.post(request, multiPart); // use your network access manager
multiPart->setParent(reply); // delete the multiPart with the reply