1. 先尝试不提供Auth进行上传,OK

1
2
3
POST http://img-1255033804.pic.ap-chengdu.myqcloud.com/filename.jpg

abc123


2. 带Auth后,出现错误。

Authorization使用的是COS签名工具生成的,API密钥使用的两个值填写的是腾讯云访问管理用户用户列表minip用户API密钥,权限给了QcloudCIFullAccessQcloudCOSFullAccess

1
2
3
4
POST http://img-1255033804.pic.ap-chengdu.myqcloud.com/auth-test.txt
Authorization: q-sign-algorithm=sha1&q-ak=AKIDviMvO4SZMBtW2RQWvLvMetEZv7KijshS&q-sign-time=1557389209;1557392809&q-key-time=1557389209;1557392809&q-header-list=&q-url-param-list=&q-signature=85dfa83edeedf866770c33633f3d256969af0715

abc123

响应:

1
2
3
4
5
6
7
8
<?xml version='1.0' encoding='utf-8' ?>
<Error>
<Code>QcloudApiRoleNotExist</Code>
<Message>Qcloud api role not exist, need create role</Message>
<Resource>img-1255033804.pic.ap-chengdu.myqcloud.com/auth-test.txt</Resource>
<RequestId>NWNkM2UzMmZfOTA0MDYzNjRfMjMyNl8zY2M=</RequestId>
<TraceId/>
</Error>


3. 换用访问密钥,请求成功

新的SecretIdSecretKey是从腾讯云访问管理访问密钥API密钥管理新建密钥(链接)得到的。生成新的Authorization后,响应如下。

1
2
3
4
5
6
<UploadResult>
<OriginalInfo>
<Key>auth-test.txt</Key>
<Location>img-1255033804.cos.ap-chengdu.myqcloud.com/auth-test.txt</Location>
</OriginalInfo>
</UploadResult>


4. 加入Pic-Operations的header之后,加入pic-operations=...生成Auth,验证不通过

1
2
3
4
5
6
7
8
9
<?xml version='1.0' encoding='utf-8' ?>
<Error>
<Code>SignatureDoesNotMatch</Code>
<Message>The Signature you specified is invalid</Message>
<StringToSign>...</StringToSign>
<Resource>img-1255033804.pic.ap-chengdu.myqcloud.com/pic-op-test.jpg</Resource>
<RequestId>NWNkM2ZjN2ZfNDQ0NjYzNjRfMzVjMl81MTk=</RequestId>
<TraceId/>
</Error>


5. 实验得知签名不应该加入HttpParametersHttpHeaders参数来生成,清除生成工具中的这两个选填字段

?image_process 可以进行云上数据处理

请求:

1
2
3
POST http://img-1255033804.pic.ap-chengdu.myqcloud.com/pic-op-test.jpg?image_process
Authorization:q-sign-algorithm=sha1&q-ak=AKIDMauCpHF4Zr360jrbs5c2LYotiL065zbj&q-sign-time=1557394879;1557398479&q-key-time=1557394879;1557398479&q-header-list=&q-url-param-list=as&q-signature=3a4482c12cb6ef86c92e853f0ecbf9e4a60562b5
Pic-Operations:{"is_pic_info":1,"rules":[{"fileid":"mytest.png","rule":"imageView2/format/png"}]}

响应:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<UploadResult>
<OriginalInfo>
<Key>pic-op-test.jpg</Key>
<Location>img-1255033804.cos.ap-chengdu.myqcloud.com/pic-op-test.jpg</Location>
<ImageInfo>
<Format>JPEG</Format>
<Width>1920</Width>
<Height>1080</Height>
<Quality>90</Quality>
<Ave>0x473a2e</Ave>
<Orientation>0</Orientation>
</ImageInfo>
</OriginalInfo>
<ProcessResults>
<Object>
<Key>mytest.png</Key>
<Location>img-1255033804.cos.ap-chengdu.myqcloud.com/mytest.png</Location>
<Format>png</Format>
<Width>1920</Width>
<Height>1080</Height>
<Size>2383168</Size>
<Quality>90</Quality>
</Object>
</ProcessResults>
</UploadResult>


6. 放在一个请求中,同时上传和处理

请求:

1
2
3
PUT http://img-1255033804.pic.ap-chengdu.myqcloud.com/pic-one.jpg
Authorization: q-sign-algorithm=sha1&q-ak=AKIDMauCpHF4Zr360jrbs5c2LYotiL065zbj&q-sign-time=1557394879;1557398479&q-key-time=1557394879;1557398479&q-header-list=&q-url-param-list=&q-signature=652f539a23fedd67a97fa7dfd909de1aea6cce8f
Pic-Operations: {"is_pic_info":1,"rules":[{"fileid":"pic_one.240x180.jpg","rule":"imageView2/1/w/240/h/180/q/85"}]}

响应:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<UploadResult>
<OriginalInfo>
<Key>pic-one.jpg</Key>
<Location>img-1255033804.cos.ap-chengdu.myqcloud.com/pic-one.jpg</Location>
<ImageInfo>
<Format>JPEG</Format>
<Width>1920</Width>
<Height>1080</Height>
<Quality>90</Quality>
<Ave>0x473a2e</Ave>
<Orientation>0</Orientation>
</ImageInfo>
</OriginalInfo>
<ProcessResults>
<Object>
<Key>pic_one.240x180.jpg</Key>
<Location>img-1255033804.cos.ap-chengdu.myqcloud.com/pic_one.240x180.jpg</Location>
<Format>JPEG</Format>
<Width>240</Width>
<Height>180</Height>
<Size>12081</Size>
<Quality>85</Quality>
</Object>
</ProcessResults>
</UploadResult>