客户管理附件oss上传

This commit is contained in:
luojiaquan
2026-10-22 11:50:32 +08:00
parent c064d925ca
commit 6fb0ba3edc
7 changed files with 100 additions and 13 deletions
@@ -29,6 +29,13 @@ public class OssStorage {
/** 使用文件流上传,避免把整个账单读入内存。返回可持久化的存储标识。 */
public String upload(Path file, String objectKey, String contentType) throws IOException {
try (InputStream input = Files.newInputStream(file)) {
return upload(input, Files.size(file), objectKey, contentType);
}
}
/** 使用输入流上传(MultipartFile 直传,不落临时文件)。返回可持久化的存储标识。 */
public String upload(InputStream input, long size, String objectKey, String contentType) throws IOException {
validateObjectKey(objectKey);
String prefix = properties.getPathPrefix();
validateObjectKey(prefix);
@@ -37,9 +44,9 @@ public class OssStorage {
}
objectKey = prefix + "/" + objectKey;
OSS client = createClient();
try (InputStream input = Files.newInputStream(file)) {
try {
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentLength(Files.size(file));
metadata.setContentLength(size);
metadata.setContentType(contentType);
metadata.setObjectAcl(CannedAccessControlList.Private);
client.putObject(new PutObjectRequest(properties.getBucket(), objectKey, input, metadata));