我发现了一个类似的问题:Google Drive API insert new file with Untitled name 但代码没有附在那里。
我的代码:
void googled::newuploadSettings(QNetworkReply *reply){
QByteArray data = reply->readAll();
qDebug() << data;
QString x = getValue(data,"access_token");
qDebug() << x;
x = "Bearer " + x;
qDebug() << x;
QNetworkRequest request;
//QString contentType = "text/plain";
QUrl url("https://www.googleapis.com/upload/drive/v2/files?uploadType=media");
//url.addQueryItem("originalFilename","sp");
request.setUrl(url);
request.setRawHeader("Content-Length","200000000");
request.setRawHeader("Content-Type","image/jpeg");
request.setRawHeader("title","sp");
//request.setRawHeader("X-Upload-Content-Length","20000000");
//request.setRawHeader("X-Upload-Content-Type","image/jpeg");
request.setRawHeader("Authorization",x.toLatin1());
//request.setRawHeader("Host","https://www.googleapis.com");
qDebug() << getValue(data,"access_token").toUtf8();
//request.setRawHeader()
QFile file("/home/saurabh/Pictures/005.jpg");
//file.setFileName("kashmir");
file.open(QIODevice::ReadOnly);
QByteArray arr = file.readAll();
file.close();
qDebug() << "file";
QString str = "a";
str.append(arr);
qDebug() << str;
m_netM = new QNetworkAccessManager;
QObject::connect(m_netM, SIGNAL(finished(QNetworkReply *)),
this, SLOT(uploadfinishedSlot(QNetworkReply *)));
m_netM->post(request,arr);
}
我知道我必须设置标题字段来为文件命名,但我无法弄清楚如何在qt中执行此操作
答案 0 :(得分:0)
标题选项应该根据Files.insert()文档
请求正文例如,如果标题有
Content-Type: application/json
请求正文
{
"title": "sp"
}
将文件的标题设置为“sp”。请查找qt文档以了解如何设置请求正文。