How can I upload files to an Amazon S3 server with qt or c++ ??
-
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'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 >.<