我正在尝试将图片上传到qt / c ++中的google-drive。 我的代码:
void googled::newuploadSettings(QNetworkReply *reply){
QByteArray m_boundary;
m_boundary = "--";
m_boundary += QString("42 + 13").toAscii();
QByteArray data = reply->readAll();
qDebug() << data;
QString x = getValue(data,"access_token");
qDebug() << x;
x = "Bearer " + x;
qDebug() << x;
QNetworkRequest request;
QUrl url("https://www.googleapis.com/upload/drive/v2/files?uploadType=multipart");
request.setUrl(url);
request.setRawHeader("Content-Length","200000000");
QString y = "multipart/related; boundary=" + QString("42+13");
qDebug() << y;
request.setRawHeader("Content-Type",y.toAscii());
request.setRawHeader("Authorization",x.toLatin1());
QString str;
str += m_boundary;
str += "\r\n";
str += "Content-Disposition: form-data; title=\"";
str += QString("sp").toAscii();
str += "\"; ";
str += "filename=\"";
str += QFile::encodeName("kashmir");
str += "\"\r\n";
str += "Content-Length: " ;
str += QString("200000000").toAscii();
str += "\r\n";
str += "Content-Type: ";
str += QString("application/json; charset=UTF-8").toAscii();
str += "\r\n";
str += "Mime-version: 1.0 ";
str += "\r\n";
str += "\r\n";
str += "mimeType:image/jpeg";
str += "\r\n";
str += "\r\n\r\n";
str += m_boundary;
str += "Content-Type: ";
str += "image/jpeg";
QByteArray arr;
arr.append(str.toUtf8());
QFile file("/home/saurabh/Pictures/005.jpg");
file.open(QIODevice::ReadOnly);
arr.append(file.readAll());
arr.append(m_boundary);
file.close();
qDebug() << "file";
//qDebug() << str;
qDebug() << arr;
m_netM = new QNetworkAccessManager;
QObject::connect(m_netM, SIGNAL(finished(QNetworkReply *)),
this, SLOT(uploadfinishedSlot(QNetworkReply *)));
m_netM->post(request,arr);
}
答案 0 :(得分:2)
您没有使用border属性的引号。使用以下内容类型:
QString y = "multipart/related; boundary=\"" + QString("42+13") + "\"";