Refine search
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()); }
/** * Loads MIME type info from the file 'mime.types' in the classpath, if it's available. */ public synchronized static Mimetypes getInstance() { if (mimetypes != null) return mimetypes; mimetypes = new Mimetypes(); InputStream is = mimetypes.getClass().getResourceAsStream("/mime.types"); if (is != null) { if (log.isDebugEnabled()) { log.debug("Loading mime types from file in the classpath: mime.types"); } try { mimetypes.loadAndReplaceMimetypes(is); } catch (IOException e) { if (log.isErrorEnabled()) { log.error("Failed to load mime types from file in the classpath: mime.types", e); } } finally { try { is.close(); } catch (IOException ex) { log.debug("", ex); } } } else { if (log.isWarnEnabled()) { log.warn("Unable to find 'mime.types' file in classpath"); } } return mimetypes; }
ObjectMetadata metadata = new ObjectMetadata(); if (this.uploadMetadataProvider != null) { this.uploadMetadataProvider.populateMetadata(metadata, requestMessage); if (payload instanceof InputStream) { InputStream inputStream = (InputStream) payload; if (metadata.getContentMD5() == null) { Assert.state(inputStream.markSupported(), "For an upload InputStream with no MD5 digest metadata, " + "the markSupported() method must evaluate to true."); String contentMd5 = Md5Utils.md5AsBase64(inputStream); metadata.setContentMD5(contentMd5); inputStream.reset(); if (metadata.getContentType() == null) { metadata.setContentType(Mimetypes.getInstance().getMimetype(fileToUpload));
InputStream input = isOrig; if (metadata == null) metadata = new ObjectMetadata(); rejectNull(bucketName, "The bucket name parameter must be specified when uploading an object"); rejectNull(key, "The key parameter must be specified when uploading an object"); } else { metadata.setContentLength(file.length()); final boolean calculateMD5 = metadata.getContentMD5() == null; if (metadata.getContentType() == null) { metadata.setContentType(Mimetypes.getInstance().getMimetype(file));
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; }
private static void loadMimeTypes() throws IOException { try (InputStream is = ProductsIngestorRunner.class.getResourceAsStream("/mime.types")) { Mimetypes.getInstance().loadAndReplaceMimetypes(is); } catch (Exception ex) { logger.error("Failed to load mime.types file!",ex); throw new RuntimeException("Failed to load mime.types!", ex); } }
/** * 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()); }
ObjectMetadata metadata = new ObjectMetadata(); if (this.uploadMetadataProvider != null) { this.uploadMetadataProvider.populateMetadata(metadata, requestMessage); if (payload instanceof InputStream) { InputStream inputStream = (InputStream) payload; if (metadata.getContentMD5() == null) { Assert.state(inputStream.markSupported(), "For an upload InputStream with no MD5 digest metadata, the " + "markSupported() method must evaluate to true. "); String contentMd5 = Md5Utils.md5AsBase64(inputStream); metadata.setContentMD5(contentMd5); inputStream.reset(); if (metadata.getContentType() == null) { metadata.setContentType(Mimetypes.getInstance().getMimetype(fileToUpload));
InputStream input = isOrig; if (metadata == null) metadata = new ObjectMetadata(); rejectNull(bucketName, "The bucket name parameter must be specified when uploading an object"); rejectNull(key, "The key parameter must be specified when uploading an object"); } else { metadata.setContentLength(file.length()); final boolean calculateMD5 = metadata.getContentMD5() == null; if (metadata.getContentType() == null) { 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()); }
putObjectRequest.setMetadata(new ObjectMetadata()); ObjectMetadata metadata = putObjectRequest.getMetadata(); metadata.setContentLength(file.length()); if ( metadata.getContentType() == null ) { metadata.setContentType(Mimetypes.getInstance().getMimetype(file));
/** * Loads MIME type info from the file 'mime.types' in the classpath, if it's available. */ public synchronized static Mimetypes getInstance() { if (mimetypes != null) return mimetypes; mimetypes = new Mimetypes(); InputStream is = mimetypes.getClass().getResourceAsStream("/mime.types"); if (is != null) { if (log.isDebugEnabled()) { log.debug("Loading mime types from file in the classpath: mime.types"); } try { mimetypes.loadAndReplaceMimetypes(is); } catch (IOException e) { if (log.isErrorEnabled()) { log.error("Failed to load mime types from file in the classpath: mime.types", e); } } finally { try { is.close(); } catch (IOException ex) { log.debug("", ex); } } } else { if (log.isWarnEnabled()) { log.warn("Unable to find 'mime.types' file in classpath"); } } return mimetypes; }
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()); }
@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); } }
String type = Mimetypes.getInstance().getMimetype(file.getName()); ObjectMetadata metadata = new ObjectMetadata(); metadata.setContentType(type); metadata.setContentLength(file.length());
String type = Mimetypes.getInstance().getMimetype(file.getName()); ObjectMetadata metadata = new ObjectMetadata(); metadata.setContentType(type); metadata.setContentLength(file.length());
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]; }