|
|
@ -177,7 +177,19 @@ public class S3ResourceRepository extends BaseResourceRepository { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void write(String path, InputStream inputStream) throws ResourceIOException { |
|
|
|
public void write(String path, InputStream inputStream) throws ResourceIOException { |
|
|
|
|
|
|
|
long dataLength = 0; |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
dataLength = inputStream.available(); |
|
|
|
|
|
|
|
} catch (IOException e) { |
|
|
|
|
|
|
|
LogKit.error(e.getMessage(), e); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//超过一定大小才使用分片上传,小文件来说,网络传输时间可能较短,且上传失败的风险相对较低。
|
|
|
|
|
|
|
|
//在网络稳定的情况下,使用分片上传可能没有太多的优势,反而增加了额外开销和复杂性
|
|
|
|
|
|
|
|
if (dataLength > MULTIPART_UPLOAD_LIMIT) { |
|
|
|
multipartUpload(path, inputStream); |
|
|
|
multipartUpload(path, inputStream); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
super.write(path, inputStream); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void multipartUpload(String path, InputStream inputStream) { |
|
|
|
private void multipartUpload(String path, InputStream inputStream) { |
|
|
|