Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    How can I upload files to an Amazon S3 server with qt or c++ ??

    General and Desktop
    c++ http qt 5.4.1
    3
    7
    5518
    Loading More Posts
    • 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.
    • S
      SujaMM last edited by

      Hello,

      I need to upload a picture to a amazon s3 in my application. I'm ussing qt 5.4.1 and c++, is there a way to do this with either qt or c++ or both.

      If it is which one it's the best option and how can I do it ??

      1 Reply Last reply Reply Quote 0
      • M
        mcosta last edited by

        HI,

        according to this S3 provide a REST API.
        You can use it with standard QNetworkAccessManager::post() requests

        Once your problem is solved don't forget to:

        • Mark the thread as SOLVED using the Topic Tool menu
        • Vote up the answer(s) that helped you to solve the issue

        You can embed images using (http://imgur.com/) or (http://postimage.org/)

        1 Reply Last reply Reply Quote 0
        • S
          SujaMM last edited by

          If I understand correctly I can upload a file to S3 with POST, but what parameters do I need to send, how do I send the credentials, key_id and secret_key ??

          1 Reply Last reply Reply Quote 0
          • M
            mcosta last edited by

            Hi,

            you have to study the API.
            To set header parameters you can use QNetworkRequest::setHeader() or QNetworkRequest::setRawHeader()

            Once your problem is solved don't forget to:

            • Mark the thread as SOLVED using the Topic Tool menu
            • Vote up the answer(s) that helped you to solve the issue

            You can embed images using (http://imgur.com/) or (http://postimage.org/)

            1 Reply Last reply Reply Quote 0
            • S
              SujaMM last edited by

              I am, but this it's all very new to me, I have to create a policy and a signature and after encode those with base64. But I'm having trouble with this part.

              Thanks for the help

              1 Reply Last reply Reply Quote 0
              • S
                SujaMM last edited by SujaMM

                I created everything I need and are working, now I'm trying to bring it to qt. But I keep getting this error:

                 Failure "Error downloading myurl - server replied: Precondition Failed"
                

                this it's the code I'm ussing, I really don'r know where the problem it's:

                // create custom temporary event loop on stack
                   QEventLoop eventLoop;
                
                // "quit()" the event-loop, when the network request "finished()"
                QNetworkAccessManager mgr;
                QNetworkCookieJar cookieJar;
                //mgr.setCookieJar(new QNetworkCookieJar(cookieJar));
                QObject::connect(&mgr, SIGNAL(finished(QNetworkReply*)), &eventLoop, SLOT(quit()));
                mgr.setCookieJar(&cookieJar);
                
                QUrl url = QUrl(QString("myurl"));
                QUrlQuery params;
                params.addQueryItem("key", "c_test/Pantallazo-2.png");
                params.addQueryItem("AWSAccessKeyId", "myAccessKeyId");
                params.addQueryItem("Policy", "mypolicy");
                params.addQueryItem("Signature", "mysignature");
                params.addQueryItem("Content-Type", "image/png");
                params.addQueryItem("file", "Pantallazo-2.png");
                
                QByteArray data;
                data = params.query(QUrl::FullyEncoded).toUtf8();
                
                QNetworkRequest request;
                request.setUrl(url);
                request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
                
                QNetworkReply *reply = mgr.post(request, data);  // POST
                eventLoop.exec(); // blocks stack until "finished()" has been called
                
                if (reply->error() == QNetworkReply::NoError) {
                    qDebug() << "Success";
                } else {
                    //failure
                    qDebug() << "Failure" <<reply->errorString();
                    delete reply;
                }
                
                I 1 Reply Last reply Reply Quote 0
                • I
                  Inathero @SujaMM last edited by

                  @SujaMM

                  I'm trying to do exactly what you're attempting to do. But in my case, all my code works except for how I create my signature (the response from aws server says that their signature is different than mine, therefore my request won't go through). If its possible, could you show me how you're creating your signature? If I can create my signature correctly and it goes through, I can post the source code for you to pick apart and choose what you want to use.

                  I just keep failing on this signature creation business >.<

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post