/** * Determines the mimetype of a file by looking up the file's extension in an internal listing * to find the corresponding mime type. If the file has no extension, or the extension is not * available in the listing contained in this class, the default mimetype * <code>application/octet-stream</code> is returned. * <p> * A file extension is one or more characters that occur after the last period (.) in the file's name. * If a file has no extension, * Guesses the mimetype of file data based on the file's extension. * * @param file * the file whose extension may match a known mimetype. * * @return * the file's mimetype based on its extension, or a default value of * <code>application/octet-stream</code> if a mime type value cannot be found. */ public String getMimetype(File file) { return getMimetype(file.getName()); }
protected final ObjectMetadata updateMetadataWithContentCryptoMaterial( ObjectMetadata metadata, File file, ContentCryptoMaterial instruction) { if (metadata == null) metadata = new ObjectMetadata(); if (file != null) { Mimetypes mimetypes = Mimetypes.getInstance(); metadata.setContentType(mimetypes.getMimetype(file)); } return instruction.toObjectMetadata(metadata, cryptoConfig.getCryptoMode()); }
metadata.setContentType(Mimetypes.getInstance().getMimetype(file));
metadata.setContentType(Mimetypes.getInstance().getMimetype(file));
/** * Determines the mimetype of a file by looking up the file's extension in an internal listing * to find the corresponding mime type. If the file has no extension, or the extension is not * available in the listing contained in this class, the default mimetype * <code>application/octet-stream</code> is returned. * <p> * A file extension is one or more characters that occur after the last period (.) in the file's name. * If a file has no extension, * Guesses the mimetype of file data based on the file's extension. * * @param file * the file whose extension may match a known mimetype. * * @return * the file's mimetype based on its extension, or a default value of * <code>application/octet-stream</code> if a mime type value cannot be found. */ public String getMimetype(File file) { return getMimetype(file.getName()); }
protected ObjectMetadata getObjectMetadata(final File source, final String destination) { // Set the mime type according to the extension of the destination file String contentType = mimeTypes.getMimetype(destination); long contentLength = source.length(); ObjectMetadata omd = new ObjectMetadata(); omd.setContentLength(contentLength); omd.setContentType(contentType); return omd; }
protected final ObjectMetadata updateMetadataWithContentCryptoMaterial( ObjectMetadata metadata, File file, ContentCryptoMaterial instruction) { if (metadata == null) metadata = new ObjectMetadata(); if (file != null) { Mimetypes mimetypes = Mimetypes.getInstance(); metadata.setContentType(mimetypes.getMimetype(file)); } return instruction.toObjectMetadata(metadata, cryptoConfig.getCryptoMode()); }
String type = Mimetypes.getInstance().getMimetype(file.getName());
String type = Mimetypes.getInstance().getMimetype(file.getName());
@Override protected void putResource(File source, String destination, TransferProgress transferProgress) throws TransferFailedException, ResourceDoesNotExistException { String key = getKey(destination); InputStream in = null; try { ObjectMetadata objectMetadata = new ObjectMetadata(); objectMetadata.setContentLength(source.length()); objectMetadata.setContentType(Mimetypes.getInstance().getMimetype(source)); in = new TransferProgressFileInputStream(source, transferProgress); this.amazonS3.putObject(new PutObjectRequest(this.bucketName, key, in, objectMetadata)); } catch (AmazonServiceException e) { throw new TransferFailedException(String.format("Cannot write file to '%s'", destination), e); } catch (FileNotFoundException e) { throw new ResourceDoesNotExistException(String.format("Cannot read file from '%s'", source), e); } finally { IoUtils.closeQuietly(in); } }
@Override protected void putResource(File source, String destination, TransferProgress transferProgress) throws TransferFailedException, ResourceDoesNotExistException { String key = getKey(destination); mkdirs(key, 0); InputStream in = null; try { ObjectMetadata objectMetadata = new ObjectMetadata(); objectMetadata.setContentLength(source.length()); objectMetadata.setContentType(Mimetypes.getInstance().getMimetype(source)); in = new TransferProgressFileInputStream(source, transferProgress); this.amazonS3.putObject(new PutObjectRequest(this.bucketName, key, in, objectMetadata)); } catch (AmazonServiceException e) { throw new TransferFailedException(String.format("Cannot write file to '%s'", destination), e); } catch (FileNotFoundException e) { throw new ResourceDoesNotExistException(String.format("Cannot read file from '%s'", source), e); } finally { IoUtils.closeQuietly(in); } }
@Override protected void putResource(File source, String destination, TransferProgress transferProgress) throws TransferFailedException, ResourceDoesNotExistException { String key = getKey(destination); mkdirs(key, 0); InputStream in = null; try { ObjectMetadata objectMetadata = new ObjectMetadata(); objectMetadata.setContentLength(source.length()); objectMetadata.setContentType(Mimetypes.getInstance().getMimetype(source)); in = new TransferProgressFileInputStream(source, transferProgress); this.amazonS3.putObject(new PutObjectRequest(this.bucketName, key, in, objectMetadata)); } catch (AmazonServiceException e) { throw new TransferFailedException(String.format("Cannot write file to '%s'", destination), e); } catch (FileNotFoundException e) { throw new ResourceDoesNotExistException(String.format("Cannot read file from '%s'", source), e); } finally { IoUtils.closeQuietly(in); } }
public ObjectMetadata buildMetadata(FilePath filePath) throws IOException, InterruptedException { ObjectMetadata metadata = new ObjectMetadata(); metadata.setContentType(Mimetypes.getInstance().getMimetype(filePath.getName())); metadata.setContentLength(filePath.length()); metadata.setLastModified(new Date(filePath.lastModified())); if ((storageClass != null) && !"".equals(storageClass)) { metadata.setHeader("x-amz-storage-class", storageClass); } if (useServerSideEncryption) { metadata.setServerSideEncryption(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION); } for (MetadataPair metadataPair : userMetadata) { metadata.addUserMetadata(metadataPair.key, metadataPair.value); } return metadata; }
metadata.setContentType(Mimetypes.getInstance().getMimetype(fileToUpload));
metadata.setContentType(Mimetypes.getInstance().getMimetype(fileToUpload));
public String saveFile(final FileUploadType file) throws ServiceException { SdkBufferedInputStream stream = null; GeneratePresignedUrlRequest request; try { stream = new SdkBufferedInputStream(file.getFile().getInputStream(), (int) (file.getFile().getSize() + 100)); String type = Mimetypes.getInstance().getMimetype(file.getFile().getOriginalFilename()); String key = getFileKey(file); ObjectMetadata metadata = new ObjectMetadata(); metadata.setContentType(type); metadata.setContentLength(file.getFile().getSize()); PutObjectRequest putRequest = new PutObjectRequest(getAmazonType().getS3Bucket(), key, stream, metadata); getAmazonType().getAmazonS3().putObject(putRequest); getAmazonType().getAmazonS3().setObjectAcl(getAmazonType().getS3Bucket(), key, CannedAccessControlList.PublicRead); request = new GeneratePresignedUrlRequest(getAmazonType().getS3Bucket(), key); } catch (IOException e) { throw new AWSException("Can't save file to Amazone", e); } finally { IOUtils.closeQuietly(stream); } return getAmazonType().getAmazonS3().generatePresignedUrl(request).toString().split("\\?")[0]; }
metadata.setContentType(Mimetypes.getInstance().getMimetype(file));
metadata.setContentType(Mimetypes.getInstance().getMimetype(file));