|
楼主 |
发表于 2022-11-3 17:08:53
|
显示全部楼层
广东省东莞市
这是java的例子
// url为获取到的上传参数中的url
URL url = new URL(uploadUrl);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setConnectTimeout(10000);
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setUseCaches(true);
conn.setRequestMethod(method);
// 上传obs需要的请求header处理
for (Map.Entry<String, String> entry : headers.entrySet()) {
conn.setRequestProperty(entry.getKey(), entry.getValue());
}
try (
DataOutputStream out = new DataOutputStream(conn.getOutputStream())) {
out.write(bufferOut, 0, len);
out.flush();
} catch (IOException ioe) {
ioe.printStackTrace();
}
conn.getResponseCode();
// 注:对于分段上传时,每个分段的上传的etag需要获取并且在compose的时候携带。
conn.getHeaderField("etag");
这是我自己写的 res = requests.put(url, data=open(file, 'rb'), headers=headers)
这是返回的数据 让我上传的
[size=15.0667px]{
[size=15.0667px] "data": {
[size=15.0667px] "headers": {
[size=15.0667px] "Authorization": "AWS4-HMAC-SHA256 Credential=OSP96VPTI1FTZRQCASWR/20221103/cn-north-2/s3/aws4_request, SignedHeaders=content-length;content-type;host;x-amz-content-sha256;x-amz-date, Signature=87c57848e61e3ece79594a5a7424a159bb5b3d89a2e2cb16e44386f9fa451ed6",
[size=15.0667px] "x-amz-content-sha256": "3E388546B1CECFFC95283EDF5BFBD8ECCD368D7BDD935FC2C7CDE1606F2CD3CB",
[size=15.0667px] "x-amz-date": "20221103T082837Z",
[size=15.0667px] "Host": "nsp-hicinema-mmpmedia-p03-drcn.obs.cn-north-2.myhuaweicloud.cn",
[size=15.0667px] "Content-Type": "image/jpeg",
[size=15.0667px] "user-agent": "Java/1.8.0_322"
[size=15.0667px] },
[size=15.0667px] "imageId": "1016633163788586880",
[size=15.0667px] "method": "PUT",
[size=15.0667px] "url": "https://nsp-hicinema-mmpmedia-p03-drcn.obs.cn-north-2.myhuaweicloud.cn/contentsrc/import/CP180163532471853117/mos/part/ff25cd69-cd6c-49e0-865e-d2fce37f0e2c.jpg"
[size=15.0667px] },
[size=15.0667px] "retCode": 0,
[size=15.0667px] "retMsg": "success"
[size=15.0667px]}
|
|