访问的Azure Blob存储使用C ++ [英] Access Azure blob storage using C++

查看:144
本文介绍了访问的Azure Blob存储使用C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

环顾四周,发现暗示我应该使用REST几个答案。不过,我将如何在Qt中/ C ++集成呢?任何人都可以链接的一些范例或code的可能是几行?真的AP preciate呢!

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!

推荐答案

我花了很多时间去实现它​​。最棘手的事情是,你必须脱code你的主键。随着这个问题的帮助下,我已经决定使用OpenSSL和我已经做了如下code。

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.

这篇关于访问的Azure Blob存储使用C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆