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.

    https://developers.google.com/cloud-print/docs/appInterfaces#submit

    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.

    http://stackoverflow.com/questions/16735595/uploading-files-using-qt-qnetworkrequest

    QByteArray WelcomeScreen::buildUploadString()
    {
    QString path;
    path.append("image.jpg");

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

    }

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

    QUrl mResultsURL = QUrl("https://www.google.com/cloudprint/submit?printerid=value");
    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("xsrf",value);
    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.

    thanks


  • 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
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.