diff --git a/src/main/java/com/fanruan/fs/s3/repository/core/S3ResourceRepository.java b/src/main/java/com/fanruan/fs/s3/repository/core/S3ResourceRepository.java index f8d05b3..c6edea8 100644 --- a/src/main/java/com/fanruan/fs/s3/repository/core/S3ResourceRepository.java +++ b/src/main/java/com/fanruan/fs/s3/repository/core/S3ResourceRepository.java @@ -175,15 +175,15 @@ public class S3ResourceRepository extends BaseResourceRepository { metadata = s3.getObjectMetadata(bucket, path); } catch (Exception ignore) { } - } - if (metadata == null) { - metadata = new ObjectMetadata(); - String mimeType = URLConnection.guessContentTypeFromName(path); - if (mimeType != null) { - metadata.setContentType(mimeType); + if (metadata == null) { + metadata = new ObjectMetadata(); + String mimeType = URLConnection.guessContentTypeFromName(path); + if (mimeType != null) { + metadata.setContentType(mimeType); + } } + metadata.setContentLength(length); } - metadata.setContentLength(length); s3.putObject(bucket, path, new ByteArrayInputStream(data), metadata); } }