fix: 腾讯云cos上传警告
This commit is contained in:
parent
fa99a4fb9b
commit
eb8cab3f5a
|
|
@ -67,6 +67,14 @@ public class TencentCosUtil {
|
|||
try {
|
||||
InputStream inputStream = file.getInputStream();
|
||||
ObjectMetadata objectMetadata = new ObjectMetadata();
|
||||
// 必须设置长度,否则底层 OkHttp 会告警「No content length specified…」并整段缓冲到内存,易 OOM
|
||||
long contentLength = file.getSize();
|
||||
if (contentLength >= 0) {
|
||||
objectMetadata.setContentLength(contentLength);
|
||||
}
|
||||
if (file.getContentType() != null && !file.getContentType().isEmpty()) {
|
||||
objectMetadata.setContentType(file.getContentType());
|
||||
}
|
||||
PutObjectRequest putObjectRequest = new PutObjectRequest(
|
||||
bucketName,
|
||||
key,
|
||||
|
|
|
|||
Loading…
Reference in New Issue