s3Client.putObject(new PutObjectRequest("your-bucket", "some-path/some-key.jpg", new File("somePath/someKey.jpg")).withCannedAcl(CannedAccessControlList.PublicRead)) s3Client.getResourceUrl("your-bucket", "some-path/some-key.jpg");
public PutObjectResult putObject(String bucket, String key, InputStream in, ObjectMetadata objectMetadata) { return putObject(new PutObjectRequest(bucket, key, in, objectMetadata)); }
public PutObjectResult putObject(String bucket, String key, File file) { return putObject(new PutObjectRequest(bucket, key, file)); }
@Override public PutObjectResult putObject(String bucketName, String key, InputStream input, ObjectMetadata metadata) throws SdkClientException, AmazonServiceException { return putObject(new PutObjectRequest(bucketName, key, input, metadata)); }
@Override public PutObjectResult putObject(String bucketName, String key, InputStream input, ObjectMetadata metadata) throws SdkClientException, AmazonServiceException { return putObject(new PutObjectRequest(bucketName, key, input, metadata)); }
@Override protected void createFile(String key, byte[] contents) throws Exception { ObjectMetadata metadata = new ObjectMetadata(); metadata.setContentLength(contents.length); PutObjectRequest request = new PutObjectRequest(bucket, key, new ByteArrayInputStream(contents), metadata); client.putObject(request); }
public PutObjectResult putObject(String bucket, String key, String content) { final InputStream in = new ByteArrayInputStream(StringUtils.toUtf8(content)); return putObject(new PutObjectRequest(bucket, key, in, new ObjectMetadata())); }
@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; } }
@Override public PutObjectResult putObject(String bucketName, String key, File file) throws SdkClientException, AmazonServiceException { return putObject(new PutObjectRequest(bucketName, key, file) .withMetadata(new ObjectMetadata())); }
@Override public PutObjectResult putObject(String bucketName, String key, File file) throws SdkClientException, AmazonServiceException { return putObject(new PutObjectRequest(bucketName, key, file) .withMetadata(new ObjectMetadata())); }
PutObjectRequest putReq = new PutObjectRequest(mBucketName, path, mFile).withMetadata(meta); mManager.upload(putReq).waitForUploadResult(); if (!mFile.delete()) {
private void uploadFileIfPossible(String bucket, String key, File file) { final PutObjectRequest indexFilePutRequest = new PutObjectRequest(bucket, key, file); if (!config.getDisableAcl()) { indexFilePutRequest.setAccessControlList(S3Utils.grantFullControlToBucketOwner(s3Client, bucket)); } log.info("Pushing [%s] to bucket[%s] and key[%s].", file, bucket, key); s3Client.putObject(indexFilePutRequest); } }
private PutObjectResult uploadFrom0(final byte[] buffer, RequestMetricCollector requestMetricCollector) { ObjectMetadata objectMetadata = new ObjectMetadata(); objectMetadata.setContentLength(buffer.length); PutObjectRequest req = new PutObjectRequest(getBucketName(), getKey(), new ByteArrayInputStream(buffer), objectMetadata) .withRequestMetricCollector(requestMetricCollector); return getAmazonS3Client().putObject(req); }
@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)); }
public static ObjectMetadata simpleUploadFile(S3Client client, byte[] bytes, String bucket, String key) throws Exception { byte[] md5 = md5(bytes, bytes.length); ObjectMetadata metadata = new ObjectMetadata(); metadata.setContentLength(bytes.length); metadata.setLastModified(new Date()); metadata.setContentMD5(S3Utils.toBase64(md5)); PutObjectRequest putObjectRequest = new PutObjectRequest(bucket, key, new ByteArrayInputStream(bytes), metadata); PutObjectResult putObjectResult = client.putObject(putObjectRequest); if ( !putObjectResult.getETag().equals(S3Utils.toHex(md5)) ) { throw new Exception("Unable to match MD5 for config"); } return metadata; } }
private PutObjectResult uploadFrom0(final File source, RequestMetricCollector requestMetricCollector) { PutObjectRequest req = new PutObjectRequest(getBucketName(), getKey(), source).withRequestMetricCollector(requestMetricCollector); return getAmazonS3Client().putObject(req); }
protected final PutObjectRequest createInstructionPutRequest( String bucketName, String key, ContentCryptoMaterial cekMaterial) { byte[] bytes = cekMaterial.toJsonString(cryptoConfig.getCryptoMode()) .getBytes(UTF8); InputStream is = new ByteArrayInputStream(bytes); ObjectMetadata metadata = new ObjectMetadata(); metadata.setContentLength(bytes.length); metadata.addUserMetadata(Headers.CRYPTO_INSTRUCTION_FILE, ""); InstructionFileId ifileId = new S3ObjectId(bucketName, key) .instructionFileId(); return new PutObjectRequest(ifileId.getBucket(), ifileId.getKey(), is, metadata); }
/** * 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); } }
STATS.uploadStarted(); PutObjectRequest request = new PutObjectRequest(host, key, tempFile); if (sseEnabled) { switch (sseType) {
/** * Creates and returns a {@link PutObjectRequest} for the instruction file * with the specified suffix. */ public PutObjectRequest createPutObjectRequest(S3Object s3Object) { if (!s3Object.getBucketName().equals(s3ObjectId.getBucket()) || !s3Object.getKey().equals(s3ObjectId.getKey())) { throw new IllegalArgumentException("s3Object passed inconsistent with the instruction file being created"); } InstructionFileId ifid= s3ObjectId.instructionFileId(suffix); // ObjectMetadata metadata = s3Object.getObjectMetadata(); return new PutObjectRequest(ifid.getBucket(), ifid.getKey(), redirectLocation) .withAccessControlList(accessControlList) .withCannedAcl(cannedAcl) // .withFile(file) // .withInputStream(inputStream) // don't want the metadata for the new instruction file // .withMetadata(metadata == null ? null : metadata.clone()) .withStorageClass(storageClass) .withGeneralProgressListener(getGeneralProgressListener()) .withRequestMetricCollector(getRequestMetricCollector()) ; } }