Closed aixi closed 4 years ago
你需要使用 iostream 的 read 接口读数据。
上面的写法仅适用于文本。
std::istream& blob(*(outcome.result().Content())); char buf[1024]; while (!blob.eof()) { blob.read(buf, sizeof(buf)); result.insert(result.end(), buf, buf + blob.gcount()); }
正确的读二进制文件的方式
GetObjectRequest request(BucketName, ObjectName); auto outcome = client.GetObject(request); if (outcome.isSuccess()) {
std::cout << "getObjectToBuffer" << " success, Content-Length:" << outcome.result().Metadata().ContentLength() << std::endl; /打印下载内容/ std::string content; (outcome.result().Content()) >> content; std::cout << "getObjectToBuffer" << "content:" << content << std::endl; } else { /异常处理*/ std::cout << "getObjectToBuffer fail" << ",code:" << outcome.error().Code() << ",message:" << outcome.error().Message() << ",requestId:" << outcome.error().RequestId() << std::endl; ShutdownSdk(); return -1; }
*(outcome.result().Content()) >> content;content中的内容很可能不全,如果有换行符之类的