我正在尝试使用 cpp sdk 在 aws s3 上上传文件列表。但是只有少数文件正在上传,并且在上传所有文件之前就被终止了。我正在使用 aws s3 cpp sdk 的上传 api。
bool OnUpload_test(bool status, const char* carouselname, void* userdata){
cout << "status" << status<< endl;
cout << "Objectname =" << carouselname << endl;
return true;
}
bool upload_thread(Proxy* proxy, const char* file,const char* path, int duration)
{
char output_file[512];
snprintf(output_file,512,"%s/%s",path,file);
proxy->Upload(file, output_file,duration,OnUpload_test,nullptr);
return true;
}
int main(){
char filename[9][128];
int i = 0, num_thread = 10,j=0,k=0;
thread *thread_count[num_thread];
Proxy *m_proxy = new Proxy("123","bucket_name",20);
//creating thread to test upload
for (int i = 1, j = 0; i<=9; i++, j++)
{
snprintf(filename[j],128,"centos%d.mp4",i);
cout << "count = " << j << endl;
thread_count[i] = new thread(upload_thread, m_proxy,(const char*) filename[j],"path",20);
}
for (i = 1; i<=9; i++)
{
thread_count[i]->join();
}
sleep(120);
}
上传函数 s3 Api 将数据上传到 s3。文件大小平均为 40 mb。我正在尝试上传 9 个文件。
///////////////////////////////////////// /////////////////
bool UploadData::Uploaddata(string bucketName, string objname, string
objdata,int duration,const char* id)
{
Aws::String bcktName(bucketName.c_str(), bucketName.size());
Aws::String obj(objname.c_str(), objname.size());
Aws::String objdt(objdata.c_str(), objdata.size());
Aws::Client::ClientConfiguration config;
config.connectTimeoutMs = 5000000;
config.requestTimeoutMs = 6000000;
const Aws::String user_region = "ap-south-1";
config.region = user_region;
Aws::S3::S3Client client(config);
Aws::S3::Model::PutObjectRequest request;
request.SetBucket(bcktName);
request.SetKey(obj);
const std::shared_ptr<Aws::IOStream> input_data = Aws::MakeShared<Aws::FStream>(obj.c_str(),objdt.c_str(),std::ios_base::in | std::ios_base::binary);
input_data->seekg(0, input_data->end);
int fsize = input_data->tellg();
input_data->seekg(0, input_data->beg);
request.SetContentLength(fsize);
request.SetBody(input_data);
auto outcome = client.PutObject(request);
if (!outcome.IsSuccess()) {
std::cout <<"UploadObject error = "<< outcome.GetError().GetMessage().c_str() << std::endl;
return false;
}
}