Skip to content

Commit

Permalink
#829 | Set mime type when uploading files to s3
Browse files Browse the repository at this point in the history
  • Loading branch information
1t5j0y committed Dec 18, 2024
1 parent baaae62 commit 91d0ea5
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import com.amazonaws.services.s3.transfer.TransferManagerBuilder;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.avni.server.domain.S3ExtensionFile;
import org.avni.server.domain.Organisation;
import org.avni.server.domain.OrganisationConfig;
import org.avni.server.domain.S3ExtensionFile;
import org.avni.server.domain.UserContext;
import org.avni.server.framework.security.UserContextHolder;
import org.avni.server.service.media.MediaFolder;
Expand Down Expand Up @@ -348,7 +348,11 @@ public String putObject(String objectKey, File tempFile) {
logger.info(format("[dev] Save file locally. '%s'", objectKey));
return tempFile.getAbsolutePath();
}
s3Client.putObject(new PutObjectRequest(bucketName, objectKey, tempFile));
String mimeType = URLConnection.guessContentTypeFromName(objectKey);
ObjectMetadata objectMetadata = new ObjectMetadata();
objectMetadata.setContentType(mimeType);
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, objectKey, tempFile).withMetadata(objectMetadata);
s3Client.putObject(putObjectRequest);
tempFile.delete();
return objectKey;
}
Expand Down

0 comments on commit 91d0ea5

Please sign in to comment.