Hello, I'm very new at qt, but I need to upload an image to a Amazon S3 server, but I keep getting this error:

Qt Code:
  1. Failure "Error downloading https://bucket_name.s3.amazonaws.com/ - server replied: Forbidden"
To copy to clipboard, switch view to plain text mode 

I check all the credencialas and keys and they are working fine because I was able to upload the image with curl comands. The problem was when I tried to implemt the code on qt5.

So this it's the code I'm ussing:

Qt Code:
  1. QEventLoop eventLoop;
  2. QNetworkAccessManager mgr;
  3. QObject::connect(&mgr, SIGNAL(finished(QNetworkReply*)), &eventLoop, SLOT(quit()));
  4.  
  5. QHttpMultiPart *multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType);
  6.  
  7. QHttpPart textPart;
  8. textPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"key\""));
  9. textPart.setBody("c_test/Pantallazo-10.jpg");
  10.  
  11. QHttpPart textPart1;
  12. textPart1.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"AWSAccessKeyId\""));
  13. textPart1.setBody("myAccessKeyId");
  14.  
  15. QHttpPart textPart2;
  16. textPart2.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"Policy\""));
  17. textPart2.setBody("myPolicy");
  18.  
  19. QHttpPart textPart3;
  20. textPart3.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"Signature\""));
  21. textPart3.setBody("mySignature");
  22.  
  23. QHttpPart imagePart;
  24. imagePart.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("image/jpeg"));
  25. imagePart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"file\""));
  26. QFile *file = new QFile(QDir::homePath() + "Pantallazo-10.jpg");
  27. file->open(QIODevice::ReadOnly);
  28. imagePart.setBodyDevice(file);
  29. file->setParent(multiPart); // we cannot delete the file now, so delete it with the multiPart
  30.  
  31. multiPart->append(textPart);
  32. multiPart->append(textPart1);
  33. multiPart->append(textPart2);
  34. multiPart->append(textPart3);
  35. multiPart->append(imagePart);
  36.  
  37. QUrl url = QUrl(QString("https://bucket_name.s3.amazonaws.com/"));
  38.  
  39. QNetworkRequest request(url);
  40. QNetworkReply *reply = mgr.post(request, multiPart); // POST
  41. eventLoop.exec(); // blocks stack until "finished()" has been called
  42.  
  43. if (reply->error() == QNetworkReply::NoError) {
  44. qDebug() << "Success";
  45. } else {
  46. //failure
  47. qDebug() << "Failure" <<reply->errorString();
  48. multiPart->setParent(reply);
  49. delete reply;
  50. }
To copy to clipboard, switch view to plain text mode 

I really don't know what to do next, I'm pretty stuck on this one.