Access Azure blob storage using C++ [closed]

99封情书 提交于 2019-12-31 07:15:09

问题


Was looking around and found a few answers that suggests that I should use REST. But how would I integrate this in Qt/c++? Could anyone link some examples of this or maybe a few lines of code? Would really appreciate it!


回答1:


It took me a lot of time to achieve it. The trickiest thing is that you have to decode your primary key. With the help of this question, I've decided to use OpenSSL and I've made the following code.

QString datastring = "GET\n\n\n\n\n\n\n\n\n\n\n\nx-ms-date:" + date + "\nx-ms-version:2009-09-19\n/myStorage/\ncomp:list";
QByteArray ba = datastring.toUtf8();

unsigned char* signature = reinterpret_cast<unsigned char*>(ba.data());
QByteArray kba = QByteArray::fromBase64("theStorageAccountKey");
unsigned char* key = (unsigned char*) kba.data();
unsigned char result[EVP_MAX_MD_SIZE];
unsigned int result_len;
ENGINE_load_builtin_engines();
ENGINE_register_all_complete();

HMAC_CTX ctx;
HMAC_CTX_init(&ctx);
HMAC_Init_ex(&ctx, key, strlen((const char*)key), EVP_sha256(), NULL);
HMAC_Update(&ctx, signature, strlen((const char*)signature));
HMAC_Final(&ctx, result, &result_len);
HMAC_CTX_cleanup(&ctx);

QByteArray array = QByteArray::fromRawData((char*)result, result_len);
array = array.toBase64();
qDebug() << "signature hash" << array;

QString version = "2009-09-19";

//requesting the list of container to Windows Azure
QNetworkAccessManager* manager = new QNetworkAccessManager();
QNetworkRequest request;
request.setUrl(QUrl("http://myStorage.blob.core.windows.net/?comp=list"));
request.setRawHeader("Authorization","SharedKey myStorage:" + array);
request.setRawHeader("x-ms-date", date.toStdString().c_str());
request.setRawHeader("x-ms-version", version.toStdString().c_str());
QNetworkReply *reply = manager->get(request);
connect(reply, SIGNAL(readyRead()), this, SLOT(manageCloudReply()));

I hope it'll help somebody.




回答2:


Please check out this question. It covers what you ask and outlines couple of freely available C++ libraries, which you could incorporate to access Azure services.



来源:https://stackoverflow.com/questions/9202092/access-azure-blob-storage-using-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!