I want to upload a PNG image with the Imgur API. When I converted a test image (png) to Base64, I got an error that it was not a valid file type. Then I took the test image from the Imgur API documentation (R0lGODlhAQABAIAAAAAAAP//yH5BAEAAAAALAAAABAAEAAAIBRAA7
), which worked for an upload, converted it to a "real" image via a converter and tested a Base64 conversion with it. However, I get a different Base64 string (R0lGODlhAQABAOKCrAAAAAAAw7/Dv8O/IcO5BAEAAAAALAAAAAABAAEAAAIBRAA7
).
Code snippet:
QNetworkAccessManager *manager = new QNetworkAccessManager(this);
QUrl url("https://api.imgur.com/3/image");
QNetworkRequest request(url);
request.setRawHeader("Authorization", "Client-ID <hereIsTheClientID>");
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
QFile image ("C:/Users/pietr/Desktop/image.gif"); // Result from converting example Base64 from Imgur API-Docs - this file can be read by photo viewers
image.open(QIODevice::ReadOnly);
QTextStream in (&image);
QByteArray imageArray = in.readAll().toUtf8().toBase64();
qDebug() << "Image data:" << imageArray;
QUrlQuery params;
params.addQueryItem("image", imageArray);
connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*)));
manager->post(request, params.query().toUtf8());
But the reply is...
{
"data":
{
"error":
{
"code":1003,
"message":"File type invalid (2)",
"type":"ImgurException",
"exception":[]},"request":"\/3\/image",
"method":"POST"
},
"success":false,
"status":400
}
Am I making a mistake with the Base64 convert? Why do I get a different value out of the same images?