海思3599A,物联网卡定向流量,使用C语言SDK liboss_c_sdk.so.3.0.0 libcurl.so.4.7.0
上传一张图片 [2020-11-18 11:55:50.922] 548278357184 /home/osstest/aliyun-oss-c-sdk-master/oss_c_sdk/oss_auth.c:288 signstr:PUT
image/jpeg Wed, 18 Nov 2020 11:55:50 GMT /puerttpark/2_PELSL0086_1142014_20201117134809_357_2.jpg. [2020-11-18 11:55:50.922] 548278357184 aos_transport.c:99 url:http://puerttpark.oss-cn-chengdu.aliyuncs.com/2_PELSL0086_1142014_20201117134809_357_2.jpg. [2020-11-18 11:55:51.097] 548278357184 aos_transport.c:28 curl:0x42e310p=> Info: Trying 47.108.6.69:80... [2020-11-18 11:55:51.205] 548278357184 aos_transport.c:28 curl:0x42e310p=> Info: Connected to puerttpark.oss-cn-chengdu.aliyuncs.com (47.108.6.69) port 80 (#0) [2020-11-18 11:55:51.205] 548278357184 aos_transport.c:31 curl:0x42e310p=> Send header: PUT /2_PELSL0086_1142014_20201117134809_357_2.jpg HTTP/1.1 Host: puerttpark.oss-cn-chengdu.aliyuncs.com User-Agent: aliyun-sdk-c/3.10.0(Compatible Unknown) Accept: / Transfer-Encoding: chunked Content-Length: 372399 Content-Type: image/jpeg Date: Wed, 18 Nov 2020 11:55:50 GMT Authorization: OSS LTAI4FxNmQbcieYnZUYogRJY:F233KSyeMmtaB2z+boaLwyQJ+Eg=
%17 %35 %52 %70 %87 %100 [2020-11-18 11:55:51.654] aos_http_io.c:194 file read finish. file_pos:372399 file_last:372399 %100 [2020-11-18 11:55:51.654] 548278357184 aos_transport.c:28 curl:0x42e310p=> Info: Signaling end of chunked upload via terminating chunk. [2020-11-18 11:56:51.887] 548278357184 aos_transport.c:28 curl:0x42e310p=> Info: Empty reply from server [2020-11-18 11:56:51.887] 548278357184 aos_transport.c:28 curl:0x42e310p=> Info: Connection #0 to host puerttpark.oss-cn-chengdu.aliyuncs.com left intact [2020-11-18 11:56:51.887] 548278357184 aos_transport.c:501 transport failure curl code:52 error:Server returned nothing (no headers, no data) [2020-11-18 11:56:51.887] 548278357184 aos_transport.c:211 has error -996.
明明已经发送成功了,为什么服务端不给返回呢? Empty reply from server
#代码
void percentage(int64_t consumed_bytes, int64_t total_bytes)
{
assert(total_bytes >= consumed_bytes);
printf("%%%" APR_INT64_T_FMT "\n", consumed_bytes * 100 / total_bytes);
}
int Upload(const char *file_name, const char *object_name, char *pic_url, const char* content_type)
{
aos_pool_t *p = NULL;
aos_string_t bucket;
aos_string_t object;
aos_string_t file;
int is_cname = 0;
aos_table_t *headers = NULL;
aos_table_t *resp_headers = NULL;
aos_list_t resp_body;
oss_request_options_t *options = NULL;
aos_status_t *s = NULL;
int ret = -1;
if(NULL == file_name || NULL == object_name)
{
return -1;
}
// 重新创建一个新的内存池,第二个参数是NULL,表示没有继承自其它内存池
aos_pool_create(&p, NULL);
//创建并初始化options,这个参数内部主要包括endpoint,access_key_id,acces_key_secret,is_cname, curl参数等全局配置信息
options = oss_request_options_create(p);
init_sample_request_options(options, is_cname, &tOssData);//tOssData是提前初始化好的一个全局变量
headers = aos_table_make(options->pool, 1);
apr_table_set(headers, OSS_CONTENT_TYPE, type);
aos_str_set(&bucket, tOssData.bucketName);
aos_str_set(&object, object_name);
aos_str_set(&file, file_name);
// 带进度上传文件
s = oss_do_put_object_from_file(options, &bucket, &object, &file, NULL, NULL, percentage, &resp_headers, &resp_body);
//s = oss_put_object_from_file(options, &bucket, &object, &file, headers, &resp_headers);
if(aos_status_is_ok(s))
{
printf("put object(%s) from file(%s) to bucket(%s) succeeded!\n",object_name, file_name, tOssData.bucketName);
ret = 0;
}
else if (aos_should_retry(s) ||
s->code == AOSE_NAME_LOOKUP_ERROR ||
s->code == AOSE_INTERNAL_ERROR ||
s->code == 403 ||s->code == 30))
{
printf("put object(%s) from file(%s) need retry, code:%d, error_code:%s, error_msg:%s, req_id:%s!\n",
object_name, file_name, s->code, s->error_code, s->error_msg, s->req_id);
ret = -9998;// 网络文件需要重传
}
else
{
printf("put object(%s) from file(%s) failed,"
"code:%d, error_code:%s, error_msg:%s, req_id:%s!\n",
object_name, file_name, s->code, s->error_code, s->error_msg, s->req_id);
if (s->code == AOSE_OPEN_FILE_ERROR ||
s->code == AOSE_FILE_INFO_ERROR ||
s->code == AOSE_FILE_READ_ERROR )
{
ret = -9999;// 文件问题不用重传
}
else
{
ret = -1;
}
}
/* 执行完一个请求后,释放掉这个内存池,结果就是会释放掉这个请求过程中各个部分分配的内存 */
aos_pool_destroy(p);
return ret;
}
int main(int argc, char **argv)
{
OssInterface::Initialize();// 会初始化SDK,这是key等等,就不公开了
const char *filename = "/mnt/data/pics/20201117/2_PELSL0086_1142014_20201117134809_357_2.jpg"; // 图片全路径
const char *objname = "2_PELSL0086_1142014_20201117134809_357_2.jpg"; // object name
char fileurl[256] = {0};// 返回的URL
int putret = -1;
ret = Upload(filename, objname, fileurl, putret, "application/x-jpg");
if(0 == ret)
{
printf("Upload [SUCCESS] URL:%s\n", fileurl);
}
else
{
printf("Upload [FAILURE], Put2OSS:%d\n", putret);
}
return 0;
}
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。