Nominate our 2022 Qt Champions!

Not able to upload file google cloud printing

  • Hi

    I am trying to upload file to google cloud printing using below link for multipart uploading.

    I am not completely clear on how to use above api (submit) for submitting document.

    Below is the my implementation till now. from the link.

    QByteArray WelcomeScreen::buildUploadString()
    QString path;

    QString bound="margin";
    QByteArray data(QString("--" + bound + "\r\n").toUtf8());
    data.append("Content-Disposition: form-data; name=\"action\"\r\n\r\n");
    data.append(QString("--" + bound + "\r\n").toUtf8());
    data.append("Content-Disposition: form-data; name=\"uploaded\"; filename=\"");
    data.append("Content-Type: image/jpg\r\n\r\n"); 
    QFile file(path);
    if (!{
        qDebug() << "QFile Error: File not found!";
        return data;
    } else {
        qDebug() << "File found, proceed as planned";
    data.append("--" + bound + "--\r\n");  
    return data;


    void WelcomeScreen::gettoken()
    QByteArray postData;
    //Look below for buildUploadString() function
    postData = buildUploadString();

    QUrl mResultsURL = QUrl("");
    QNetworkAccessManager* mNetworkManager = new QNetworkAccessManager(this);
    QString bound="margin"; //name of the boundary
    QNetworkRequest request(mResultsURL);
    request.setRawHeader(QString("Content-Type").toUtf8(),QString("multipart/form-data; boundary=" + bound).toUtf8());
    request.setRawHeader(QString("Content-Length").toUtf8(), QString::number(postData.length()).toUtf8());
    request.setRawHeader("Authorization: OAuth ",value);
    QNetworkReply *reply = mNetworkManager->post(request,postData);
    QNetworkReply::NetworkError error = reply->error();
    QString err = reply->errorString();
    QByteArray bts = reply->readAll();

    In errorstring iam getting value "NoError". that is strange for me.


  • Moderators

    always when working with QNetworkAccessManager/QNetworkReply you need to wait until the QNAM or the reply triggers it's finished signal.

    Means QNetworkAccessManager::post() is not blocking and returns immediately and is just scheduling the request which actual transfer will shortly after but your code continues. So reading the error right after you posted the request of course returns no error.

  • I am getting contentoperationnotpermitted error. cause is not clear to me. I am generating zsrf token and accesstoken from google playground 2.0

Log in to reply