@Override protected boolean createEmptyObject(String key) { try { ObjectMetadata meta = new ObjectMetadata(); meta.setContentLength(0); meta.setContentMD5(DIR_HASH); meta.setContentType(Mimetypes.MIMETYPE_OCTET_STREAM); mClient.putObject( new PutObjectRequest(mBucketName, key, new ByteArrayInputStream(new byte[0]), meta)); return true; } catch (AmazonClientException e) { LOG.error("Failed to create object: {}", key, e); return false; } }
meta.setContentType(Mimetypes.MIMETYPE_OCTET_STREAM);
@Override public PutObjectResult putObject(String bucketName, String key, String content) throws AmazonServiceException, SdkClientException { rejectNull(bucketName, "Bucket name must be provided"); rejectNull(key, "Object key must be provided"); rejectNull(content, "String content must be provided"); byte[] contentBytes = content.getBytes(StringUtils.UTF8); InputStream is = new ByteArrayInputStream(contentBytes); ObjectMetadata metadata = new ObjectMetadata(); metadata.setContentType("text/plain"); metadata.setContentLength(contentBytes.length); return putObject(new PutObjectRequest(bucketName, key, is, metadata)); }
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()); }
/** * Uploads the payload to the given s3 object key. * It is expected that the caller retrieves the object key using {@link #getLocation(Operation, PayloadType, String)} before making this call. * * @param path the s3 key of the object to be uploaded * @param payload an {@link InputStream} containing the json payload which is to be uploaded * @param payloadSize the size of the json payload in bytes */ @Override public void upload(String path, InputStream payload, long payloadSize) { try { ObjectMetadata objectMetadata = new ObjectMetadata(); objectMetadata.setContentType(CONTENT_TYPE); objectMetadata.setContentLength(payloadSize); PutObjectRequest request = new PutObjectRequest(bucketName, path, payload, objectMetadata); s3Client.putObject(request); } catch (SdkClientException e) { String msg = "Error communicating with S3"; logger.error(msg, e); throw new ApplicationException(ApplicationException.Code.BACKEND_ERROR, msg, e); } }
/** * Initializes multipart upload. */ private void initMultiPartUpload() throws IOException { // Generate the object metadata by setting server side encryption, md5 checksum, // and encoding as octet stream since no assumptions are made about the file type ObjectMetadata meta = new ObjectMetadata(); if (mSseEnabled) { meta.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION); } if (mHash != null) { meta.setContentMD5(Base64.encodeAsString(mHash.digest())); } meta.setContentType(Mimetypes.MIMETYPE_OCTET_STREAM); AmazonClientException lastException; InitiateMultipartUploadRequest initRequest = new InitiateMultipartUploadRequest(mBucketName, mKey).withObjectMetadata(meta); do { try { mUploadId = mClient.initiateMultipartUpload(initRequest).getUploadId(); return; } catch (AmazonClientException e) { lastException = e; } } while (mRetryPolicy.attempt()); // This point is only reached if the operation failed more // than the allowed retry count throw new IOException("Unable to init multipart upload to " + mKey, lastException); }
om.setContentType( mimeType ); PutObjectResult result = null; result = getS3Client().putObject( bucketName, uploadFileName, awsInputStream, om );
@Override public void addFile(String merchantStoreCode, InputContentFile inputStaticContentData) throws ServiceException { try { // get buckets String bucketName = bucketName(); String nodePath = nodePath(merchantStoreCode, inputStaticContentData.getFileContentType()); final AmazonS3 s3 = s3Client(); ObjectMetadata metadata = new ObjectMetadata(); metadata.setContentType(inputStaticContentData.getMimeType()); PutObjectRequest request = new PutObjectRequest(bucketName, nodePath + inputStaticContentData.getFileName(), inputStaticContentData.getFile(), metadata); request.setCannedAcl(CannedAccessControlList.PublicRead); s3.putObject(request); LOGGER.info("Content add file"); } catch (final Exception e) { LOGGER.error("Error while adding file", e); throw new ServiceException(e); } }
@Override public void addProductImage(ProductImage productImage, ImageContentFile contentImage) throws ServiceException { try { // get buckets String bucketName = bucketName(); final AmazonS3 s3 = s3Client(); String nodePath = this.nodePath(productImage.getProduct().getMerchantStore().getCode(), productImage.getProduct().getSku(), contentImage); ObjectMetadata metadata = new ObjectMetadata(); metadata.setContentType(contentImage.getMimeType()); PutObjectRequest request = new PutObjectRequest(bucketName, nodePath + productImage.getProductImage(), contentImage.getFile(), metadata); request.setCannedAcl(CannedAccessControlList.PublicRead); s3.putObject(request); LOGGER.info("Product add file"); } catch (final Exception e) { LOGGER.error("Error while removing file", e); throw new ServiceException(e); } }
.evaluateAttributeExpressions(ff).getValue(); if (contentType != null) { objectMetadata.setContentType(contentType); attributes.put(S3_CONTENT_TYPE, contentType);
metadata.setContentType(Mimetypes.getInstance().getMimetype(file)); metadata.setContentType(Mimetypes.MIMETYPE_OCTET_STREAM);
metadata.setContentType(Mimetypes.getInstance().getMimetype(file));
newObjectMetadata.setContentType(metadata.getContentType());
@Override public PutObjectResult putObject(String bucketName, String key, String content) throws AmazonServiceException, AmazonClientException { assertParameterNotNull(bucketName, "Bucket name must be provided"); assertParameterNotNull(key, "Object key must be provided"); assertParameterNotNull(content, "String content must be provided"); final byte[] contentBytes = content.getBytes(StringUtils.UTF8); final InputStream is = new ByteArrayInputStream(contentBytes); final ObjectMetadata metadata = new ObjectMetadata(); metadata.setContentType("text/plain"); metadata.setContentLength(contentBytes.length); return putObject(new PutObjectRequest(bucketName, key, is, metadata)); }
protected final ObjectMetadata updateMetadataWithContentCryptoMaterial( ObjectMetadata metadata, File file, ContentCryptoMaterial instruction) { if (metadata == null) { metadata = new ObjectMetadata(); } if (file != null) { final Mimetypes mimetypes = Mimetypes.getInstance(); metadata.setContentType(mimetypes.getMimetype(file)); } return instruction.toObjectMetadata(metadata, cryptoConfig.getCryptoMode()); }
LOG.debug("{} Using content headers {} for file {}", logIdentifier, contentHeaders, file); if (contentHeaders.getContentType().isPresent()) { objectMetadata.setContentType(contentHeaders.getContentType().get());
om.setContentType(upload.headerContentType); } else { om.setContentType(Mimetypes.getInstance().getMimetype(file));
/** * Update the request's ObjectMetadata with the necessary information for * decrypting the object * * @param request Non-null PUT request encrypted using the given instruction * @param instruction Non-null instruction used to encrypt the data in this * PUT request. */ public static void updateMetadataWithEncryptionInstruction(PutObjectRequest request, EncryptionInstruction instruction) { byte[] keyBytesToStoreInMetadata = instruction.getEncryptedSymmetricKey(); Cipher symmetricCipher = instruction.getSymmetricCipher(); Map<String, String> materialsDescription = instruction.getMaterialsDescription(); ObjectMetadata metadata = request.getMetadata(); if (metadata == null) metadata = new ObjectMetadata(); if (request.getFile() != null) { Mimetypes mimetypes = Mimetypes.getInstance(); metadata.setContentType(mimetypes.getMimetype(request.getFile())); } updateMetadata(metadata, keyBytesToStoreInMetadata, symmetricCipher, materialsDescription); request.setMetadata(metadata); }
metadata.setContentType(Mimetypes.getInstance().getMimetype(file));
newObjectMetadata.setContentType(metadata.getContentType());