首页
最新活动
服务器租用
香港服务器租用
台湾服务器租用
美国服务器租用
日本服务器租用
新加坡服务器租用
高防服务器
香港高防服务器
台湾高防服务器
美国高防服务器
裸金属
香港裸金属服务器
台湾裸金属服务器
美国裸金属服务器
日本裸金属服务器
新加坡裸金属服务器
云服务器
香港云服务器
台湾云服务器
美国云服务器
日本云服务器
CDN
CDN节点
CDN带宽
CDN防御
CDN定制
行业新闻
官方公告
香港服务器资讯
帮助文档
wp博客
zb博客
服务器资讯
联系我们
关于我们
机房介绍
机房托管
登入
注册
帮助文档
专业提供香港服务器、香港云服务器、香港高防服务器租用、香港云主机、台湾服务器、美国服务器、美国云服务器vps租用、韩国高防服务器租用、新加坡服务器、日本服务器租用 一站式全球网络解决方案提供商!专业运营维护IDC数据中心,提供高质量的服务器托管,服务器机房租用,服务器机柜租用,IDC机房机柜租用等服务,稳定、安全、高性能的云端计算服务,实时满足您的多样性业务需求。 香港大带宽稳定可靠,高级工程师提供基于服务器硬件、操作系统、网络、应用环境、安全的免费技术支持。
联系客服
服务器资讯
/
香港服务器租用
/
香港VPS租用
/
香港云服务器
/
美国服务器租用
/
台湾服务器租用
/
日本服务器租用
/
官方公告
/
帮助文档
Windows下Qt使用AWS SDK for C++连接MinIO服务器
发布时间:2024-03-09 18:36:49 分类:帮助文档
Windows下Qt使用AWS SDK for C++连接MinIO服务器 Windows下Qt使用AWS SDK for C++连接MinIO服务器 安装vcpkg安装AWS SDK for C++创建Qt项目对接MinIO运行 MinIO——分布式对象存储服务器。 它是一个是一个高性能的对象存储服务器,用于构建云存储解决方案,出于工作需求用到了这个MinIO来管理文件。 但,我用的是Qt,c++语言,并且使用环境是windows,可MinIO的C++ SDK只能Linux使用,不支持Windows,如果非要自己编译Windows版本的话估计得踩不少坑,放过自己吧。 最后只能折中于使用AWS SDK for C++,好在MinIO是兼容AWS SDK的? 安装vcpkg 先安装AWS SDK for C++,需要先安装vcpkg: git clone https://github.com/Microsoft/vcpkg.git cd vcpkg ./bootstrap-vcpkg.bat 等安装完成后,将vcpkg的环境加入系统环境变量,这样才能在cmd窗口随意使用vcpkg命令。 右键“我的电脑” >> 属性 >> 高级系统设置 >> 环境变量 >> 系统变量>> path 双击“path”把vcpkg的环境加入其中。 添加完成后,一路点击“确定”按钮退出界面。 安装AWS SDK for C++ 按下win+R输入cmd回车,打开窗口后,输入以下命令: vcpkg search aws-sdk-cpp vcpkg install aws-sdk-cpp[s3]:x64-windows 这里可能会因为网络问题下载包失败,失败后重来,总会成功的。 等成功安装后,会在vcpkg中看到这样一个路径:D:\Soft\vcpkg\vcpkg\installed\x64-windows 这里面lib、include、bin文件夹中的内容,就是我们需要的。 创建Qt项目 随便创建一个qt项目,在pro文件中加入: INCLUDEPATH += D:/Soft/vcpkg/vcpkg/installed/x64-windows/include LIBS += -LD:/Soft/vcpkg/vcpkg/installed/x64-windows/lib -laws-cpp-sdk-core -laws-c-auth -laws-c-cal -laws-c-common \ -laws-c-compression -laws-c-event-stream -laws-checksums -laws-c-http -laws-c-io \ -laws-cpp-sdk-dynamodb -laws-cpp-sdk-kinesis -laws-cpp-sdk-s3 -laws-crt-cpp 对接MinIO 使用aws-sdk-cpp的接口,连接MinIO服务器,要确保服务器已打开。 完成功能:连接服务器、创建Bucket、列出Buckets的名字、上传文件、下载文件、删除文件、删除Bucket。 #include
#include
#include
#include
#include
#include
#include
#include
#include
void DemoQML::initMinIO() { // 连接服务器 Aws::SDKOptions options; options.loggingOptions.logLevel = Aws::Utils::Logging::LogLevel::Debug; Aws::InitAPI(options); Aws::Client::ClientConfiguration cfg; cfg.endpointOverride = "127.0.0.1:9000"; cfg.scheme = Aws::Http::Scheme::HTTP; cfg.verifySSL = false; Aws::Auth::AWSCredentials cred("hualongxunda", "hualongxunda"); Aws::S3::S3Client client(cred, cfg, Aws::Client::AWSAuthV4Signer::PayloadSigningPolicy::Always, false, Aws::S3::US_EAST_1_REGIONAL_ENDPOINT_OPTION::NOT_SET); std::string fileName = "2104616062021073019firstpush_00004893_OK.bmp"; std::string BucketName = "mybucket"; // 创建Bucket Aws::S3::Model::CreateBucketRequest create_bucket_request; create_bucket_request.SetBucket(BucketName); create_bucket_request.SetCreateBucketConfiguration({}); auto create_bucket_outcome = client.CreateBucket(create_bucket_request); if (create_bucket_outcome.IsSuccess()) { qDebug() << "Bucket created successfully."; } else { qDebug() << "Failed to create bucket: " << create_bucket_outcome.GetError().GetMessage().c_str(); Aws::ShutdownAPI(options); return; } // 列出Buckets的名字 auto response = client.ListBuckets(); if (response.IsSuccess()) { auto buckets = response.GetResult().GetBuckets(); for (auto iter = buckets.begin(); iter != buckets.end(); ++iter) { qDebug() << "--" << iter->GetName().c_str() << iter->GetCreationDate().ToLocalTimeString(Aws::Utils::DateFormat::ISO_8601).c_str(); } } // 上传文件 QFile file(QString::fromStdString(fileName)); file.open(QIODevice::ReadOnly); Aws::S3::Model::PutObjectRequest putObjectRequest; putObjectRequest.WithBucket(BucketName.c_str()).WithKey(fileName.c_str()); std::shared_ptr
input_data = Aws::MakeShared
("PutObjectInputStream"); *input_data << file.readAll().toStdString(); file.close(); putObjectRequest.SetBody(input_data); auto putObjectResult = client.PutObject(putObjectRequest); if (putObjectResult.IsSuccess()) { qDebug() << "upload file success!"; } else { qDebug() << "upload file error: " << putObjectResult.GetError().GetExceptionName().c_str() << " " << putObjectResult.GetError().GetMessage().c_str(); Aws::ShutdownAPI(options); return; } // 下载文件 Aws::S3::Model::GetObjectRequest object_request; object_request.WithBucket(BucketName.c_str()).WithKey(fileName.c_str()); auto get_object_outcome = client.GetObject(object_request); if (get_object_outcome.IsSuccess()) { Aws::IOStream &local_file = get_object_outcome.GetResult().GetBody(); if (!local_file) { qDebug() << "Error opening file"; Aws::ShutdownAPI(options); return; } std::istreambuf_iterator
begin(local_file); std::istreambuf_iterator
end; std::string buffer(begin, end); // 读取整个文件内容 QFile file_(QString::fromStdString("./test/"+fileName)); if(file_.open(QIODevice::ReadWrite | QIODevice::Truncate)){ file_.write(QByteArray::fromStdString(buffer)); file_.close(); } qDebug() << "download success!"; } else { std::cout << "GetObject error: " << get_object_outcome.GetError().GetExceptionName() << " " << get_object_outcome.GetError().GetMessage() << std::endl; } // 删除文件 Aws::S3::Model::DeleteObjectRequest delete_object_request; delete_object_request.WithBucket(BucketName.c_str()).WithKey(fileName.c_str()); auto delete_object_outcome = client.DeleteObject(delete_object_request); if (delete_object_outcome.IsSuccess()) { qDebug() << "File deleted successfully."; } else { qDebug() << "Failed to delete file: " << delete_object_outcome.GetError().GetMessage().c_str(); } // 删除Bucket,一定要先删除文件,再删除Bucket Aws::S3::Model::DeleteBucketRequest delete_bucket_request; delete_bucket_request.SetBucket(BucketName.c_str()); auto delete_bucket_outcome = client.DeleteBucket(delete_bucket_request); if (delete_bucket_outcome.IsSuccess()) { qDebug() << "Bucket deleted successfully."; } else { qDebug() << "Failed to delete bucket: " << delete_bucket_outcome.GetError().GetMessage().c_str(); } Aws::ShutdownAPI(options); } 运行 编译release版本后,如果运行失败,可以将D:\Soft\vcpkg\vcpkg\installed\x64-windows\bin 目录下有用到的dll文件,复制到qt程序的exe同级目录下。
上一篇
香港新世界cn2机房
下一篇
主机屋 取消香港
相关文章
解决如何打开端口的问题
ubuntu 磁盘挂载
服务器故障与管理口与raid
银河麒麟V10SP1服务器系统同步外网源到本地
vscode+ssh连接远程linux系统服务器,并用anaconda管理python环境
公司服务器地址怎么查
linux 切换用户报错:This account is currently not available
服务器租用再升级:抓住云时代,享受高速稳定体验
centos 新硬盘怎么分区挂载使用
香港云服务器租用推荐
服务器租用资讯
·git云服务器,git服务器管理工具
·git服务器云服务,git服务器启动命令
·git登录腾讯云服务器,github腾讯云函数部署
·git本地服务器云服务器,git连接服务器
·ftp怎么连接阿里云服务器,ftp怎么连接阿里云服务器网络
·ftp链接阿里云服务器,ftp链接阿里云服务器怎么用
·ftp连接云服务器,云服务器搭建ftp服务器
·ftp连接阿里云服务器,阿里云虚拟主机ftp无法连接
·ftp服务器云服务器,ftp服务器云服务器怎么用
服务器租用推荐
·美国服务器租用
·台湾服务器租用
·香港云服务器租用
·香港裸金属服务器
·香港高防服务器租用
·香港服务器租用特价
7*24H在线售后
高可用资源,安全稳定
1v1专属客服对接
无忧退款试用保障
德讯电讯股份有限公司
电话:00886-982-263-666
台湾总部:台北市中山区建国北路一段29号3楼
香港分公司:九龙弥敦道625号雅兰商业二期906室
服务器租用
香港服务器
日本服务器
台湾服务器
美国服务器
高防服务器购买
香港高防服务器出租
台湾高防服务器租赁
美国高防服务器DDos
云服务器
香港云服务器
台湾云服务器
美国云服务器
日本云服务器
行业新闻
香港服务器租用
服务器资讯
香港云服务器
台湾服务器租用
zblog博客
香港VPS
关于我们
机房介绍
联系我们
Copyright © 1997-2024 www.hkstack.com All rights reserved.