application/x-www-form-urlencoded; charset=utf-8
To change this you can do something like this :
- static AmazonS3 s3Client = new AmazonS3Client(new ProfileCredentialsProvider());
- public void validateKeyContentType(String key) {
- try {
- ObjectMetadata metadata = generateCorrectContentTypeObjMetaFromKeyName(key);
- final CopyObjectRequest request = new CopyObjectRequest(bucket, key, bucket, key).withSourceBucketName(bucket)
- .withSourceKey(key)
- .withNewObjectMetadata(metadata).withCannedAccessControlList(CannedAccessControlList.PublicRead);
- s3Client.copyObject(request);
- } catch (Exception exception) {
- LOG.info(exception.getMessage());
- }
- }
- public ObjectMetadata generateCorrectContentTypeObjMetaFromKeyName(String key){
- ObjectMetadata metadata = new ObjectMetadata();
- String contentType = getFileContentTypeFromFileName(key);
- LOG.log(Level.INFO, "Setting content type : " + contentType);
- metadata.setContentType(contentType);
- return metadata;
- }
- /*
- These method takes some argument like "bucket1uploads/file100.mp4" and returns it's content type "video/mp4" by parsing the text (javax.activation)
- */
- public static String getFileContentTypeFromFileName(String filePath) {
- //javax.activation is too old and misses these content types
- MimetypesFileTypeMap ftmp = new MimetypesFileTypeMap();
- ftmp.addMimeTypes("audio/mp3 mp3 MP3");
- ftmp.addMimeTypes("video/mp4 mp4 MP4");
- ftmp.addMimeTypes("video/mkv mkv MKV");
- ftmp.addMimeTypes("video/webm webm WEBM");
- ftmp.addMimeTypes("video/flv flv FLV");
- ftmp.addMimeTypes("video/x-flv x-flv X-FLV");
- return ftmp.getContentType(filePath);
- }
No comments:
Post a Comment