0

I found a similar question: Google Drive API insert new file with Untitled name but code is not attached there.

My code:

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);

}

I know I have to set title field for giving name to file but am not able to figure out how I would do it in qt

Cœur
  • 37,241
  • 25
  • 195
  • 267
saurabh
  • 110
  • 3
  • 12
  • I've rollback your replacement of the question by the solution. Please find [your solution in the revision history](https://stackoverflow.com/revisions/37df52ae-eef3-4aba-9771-b1329f5f2b01/view-source) and post it as an answer of its own. – Cœur May 13 '18 at 14:54

1 Answers1

0

title option should go to request body according to Files.insert() documentation

For instance, if header has

Content-Type: application/json

request body would be

{
  "title": "sp"
}

To set title of the file to be "sp". Please look for qt documentation to find how to set request body.

JunYoung Gwak
  • 2,967
  • 3
  • 21
  • 35