开发者社区> 问答> 正文

[必现]特定文件特定设备中上传OSS必定失败

环境

海思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.

进行的其他测试

  1. 将文件改名上传,结果:失败
  2. 用其他文件替换现在的文件,结果:成功
  3. 将文件放到其他设备中上传,结果:成功
  4. 设置超时时间到30秒32Byte, 结果失败 总结:只要是在这个机器里上传这张图片必定失败。在这个机器里上传其他图片成功。在其他机器里上传这张图片也hui成功。

问题

明明已经发送成功了,为什么服务端不给返回呢? 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;
}

展开
收起
1647141405909324 2020-11-30 11:43:04 1115 0
1 条回答
写回答
取消 提交回答
  • 下一站是幸福

    上传阿里云 需要oss地址,下载使用cnd 地址。

    因为阿里那边做了限制

    2021-04-02 22:09:05
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
OSS运维进阶实战手册 立即下载
《OSS运维基础实战手册》 立即下载
OSS运维基础实战手册 立即下载