Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Not able to upload file google cloud printing
Forum Updated to NodeBB v4.3 + New Features

Not able to upload file google cloud printing

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 848 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • bhupiB Offline
    bhupiB Offline
    bhupi
    wrote on last edited by bhupi
    #1

    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

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      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.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      2
      • bhupiB Offline
        bhupiB Offline
        bhupi
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved