Example usage for com.amazonaws.services.s3.model ObjectMetadata ObjectMetadata

List of usage examples for com.amazonaws.services.s3.model ObjectMetadata ObjectMetadata

Introduction

In this page you can find the example usage for com.amazonaws.services.s3.model ObjectMetadata ObjectMetadata.

Prototype

public ObjectMetadata() 

Source Link

Usage

From source file:org.apache.zeppelin.notebook.repo.S3NotebookRepo.java

License:Apache License

@Override
public void save(Note note, AuthenticationInfo subject) throws IOException {
    String json = note.toJson();/*from w  ww.  jav a2 s.  c o  m*/
    String key = rootFolder + "/" + buildNoteFileName(note);
    File file = File.createTempFile("note", "zpln");
    try {
        Writer writer = new OutputStreamWriter(new FileOutputStream(file));
        writer.write(json);
        writer.close();
        PutObjectRequest putRequest = new PutObjectRequest(bucketName, key, file);
        if (useServerSideEncryption) {
            // Request server-side encryption.
            ObjectMetadata objectMetadata = new ObjectMetadata();
            objectMetadata.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION);
            putRequest.setMetadata(objectMetadata);
        }
        s3client.putObject(putRequest);
    } catch (AmazonClientException ace) {
        throw new IOException("Unable to store note in S3: " + ace, ace);
    } finally {
        FileUtils.deleteQuietly(file);
    }
}

From source file:org.apereo.portal.portlets.dynamicskin.storage.s3.AwsS3DynamicSkinService.java

License:Apache License

private ObjectMetadata createObjectMetadata(final String content, final DynamicSkinInstanceData data) {
    final ObjectMetadata metadata = new ObjectMetadata();
    this.addContentMetadata(metadata, content);
    this.addUserMetatadata(metadata);
    this.addPortletPreferenceMetadata(metadata, data.getPortletRequest().getPreferences());
    this.addDynamicSkinMetadata(metadata, data);
    return metadata;
}

From source file:org.broadleafcommerce.vendor.amazon.s3.S3FileServiceProvider.java

License:Apache License

protected void addOrUpdateResourcesInternalStreamVersion(S3Configuration s3config, AmazonS3Client s3,
        InputStream inputStream, String fileName, long fileSizeInBytes) {
    final String bucketName = s3config.getDefaultBucketName();

    final ObjectMetadata metadata = new ObjectMetadata();
    metadata.setContentLength(fileSizeInBytes);
    final String resourceName = buildResourceName(s3config, fileName);
    final PutObjectRequest objToUpload = new PutObjectRequest(bucketName, resourceName, inputStream, metadata);

    if ((s3config.getStaticAssetFileExtensionPattern() != null)
            && s3config.getStaticAssetFileExtensionPattern().matcher(getExtension(fileName)).matches()) {
        objToUpload.setCannedAcl(CannedAccessControlList.PublicRead);
    }/*w  w w .j  av a 2 s.  c om*/

    s3.putObject(objToUpload);

    if (LOG.isTraceEnabled()) {
        final String s3Uri = String.format("s3://%s/%s", s3config.getDefaultBucketName(), resourceName);
        final String msg = String.format("%s copied/updated to %s", fileName, s3Uri);

        LOG.trace(msg);
    }
}

From source file:org.caboclo.clients.AmazonClient.java

License:Open Source License

private void mkdir(String path) {
    ObjectMetadata om = new ObjectMetadata();
    om.setLastModified(new Date());
    om.setContentLength(0);//from   w w  w.  j  a v a 2s. c  o  m
    om.setContentType("inode/directory");
    ByteArrayInputStream bis = new ByteArrayInputStream(new byte[0]);

    s3.putObject(getBucketName(), path, bis, om);

    System.out.println("Creating Directory: " + path);
}

From source file:org.caboclo.clients.AmazonClient.java

License:Open Source License

@Override
public void putFile(File file, String path) throws IOException {
    ObjectMetadata om = new ObjectMetadata();
    om.setLastModified(new Date());
    om.setContentType(URLConnection.guessContentTypeFromName(file.getName()));
    om.setContentLength(file.length());//  ww w  .  j a  v  a2s  . co  m
    BufferedInputStream stream = new BufferedInputStream(new FileInputStream(file));

    s3.putObject(getBucketName(), path, stream, om);

}

From source file:org.caboclo.clients.AmazonClient.java

License:Open Source License

void createFolder(String bucketName, String path) {
    ObjectMetadata om = new ObjectMetadata();
    om.setLastModified(new Date());
    om.setContentLength(0);//  w w w. j  a v  a  2s  .c  o  m
    om.setContentType("inode/directory");
    ByteArrayInputStream bis = new ByteArrayInputStream(new byte[0]);

    s3.putObject(bucketName, path, bis, om);

    System.out.println("Creating folder: " + path);
}

From source file:org.chodavarapu.jgitaws.repositories.PackRepository.java

License:Eclipse Distribution License

public DfsOutputStream savePack(String repositoryName, String packName, long length) throws IOException {
    PipedInputStream pipedInputStream = new PipedInputStream(configuration.getStreamingBlockSize());

    ObjectMetadata metaData = new ObjectMetadata();
    metaData.setContentLength(length);//from  w w w .ja v a  2 s . com

    String objectName = objectName(repositoryName, packName);

    Async.fromAction(() -> {
        logger.debug("Attempting to save pack {} to S3 bucket", objectName);
        try {
            configuration.getS3Client().putObject(configuration.getPacksBucketName(), objectName,
                    pipedInputStream, metaData);
        } catch (AmazonServiceException e) {
            if ("InvalidBucketName".equals(e.getErrorCode()) || "InvalidBucketState".equals(e.getErrorCode())) {
                logger.debug("S3 packs bucket does not exist yet, creating it");
                configuration.getS3Client()
                        .createBucket(new CreateBucketRequest(configuration.getPacksBucketName()));
                configuration.getS3Client().setBucketVersioningConfiguration(
                        new SetBucketVersioningConfigurationRequest(configuration.getPacksBucketName(),
                                new BucketVersioningConfiguration(BucketVersioningConfiguration.OFF)));

                logger.debug("Created bucket, saving pack {}", objectName);
                configuration.getS3Client().putObject(configuration.getPacksBucketName(), objectName,
                        pipedInputStream, metaData);
            } else {
                throw e;
            }
        }
    }, null, Schedulers.io());

    return new PipedDfsOutputStream(pipedInputStream, objectName, (int) length,
            configuration.getStreamingBlockSize());
}

From source file:org.clothocad.phagebook.adaptors.S3Adapter.java

private static void createS3Folder(String bucketName, String folderName, AmazonS3 client) {
    // create meta-data for your folder and set content-length to 0
    ObjectMetadata metadata = new ObjectMetadata();
    metadata.setContentLength(0);/*from  w  ww. j  av  a  2s . c om*/
    // create empty content
    InputStream emptyContent = new ByteArrayInputStream(new byte[0]);
    // create a PutObjectRequest passing the folder name suffixed by /
    PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, folderName + "/", emptyContent,
            metadata); //folder name should be clothoID
    // send request to S3 to create folder
    client.putObject(putObjectRequest.withCannedAcl(CannedAccessControlList.PublicRead));

}

From source file:org.cloudifysource.esc.driver.provisioning.privateEc2.AmazonS3Uploader.java

License:Open Source License

/**
 * Upload file./*from  w  w w. j  ava  2s  .  co  m*/
 * 
 * @param bucketFullPath
 *            The path of the bucket where to download the file.
 * @param file
 *            The file to upload.
 * @return The URL to access the file in s3
 */
public S3Object uploadFile(final String bucketFullPath, final File file) {
    final BucketLifecycleConfiguration.Rule ruleArchiveAndExpire = new BucketLifecycleConfiguration.Rule()
            .withId("Delete cloudFolder archives").withPrefix(this.extractPrefix(bucketFullPath) + ZIP_PREFIX)
            .withExpirationInDays(1).withStatus(BucketLifecycleConfiguration.ENABLED.toString());
    final List<BucketLifecycleConfiguration.Rule> rules = new ArrayList<BucketLifecycleConfiguration.Rule>();
    rules.add(ruleArchiveAndExpire);
    final BucketLifecycleConfiguration configuration = new BucketLifecycleConfiguration().withRules(rules);
    this.s3client.setBucketLifecycleConfiguration(bucketFullPath, configuration);

    final PutObjectRequest putObjectRequest = new PutObjectRequest(bucketFullPath, this.accessKey, file);
    putObjectRequest.setKey(file.getName());
    final ObjectMetadata metadata = new ObjectMetadata();
    putObjectRequest.setMetadata(metadata);
    this.s3client.putObject(putObjectRequest);

    final S3Object object = this.s3client.getObject(bucketFullPath, file.getName());
    return object;
}

From source file:org.cm.podd.report.service.DataSubmitService.java

License:Apache License

private boolean uploadToS3(String guid, String filePath, Bitmap thumbnail) {
    TransferManager transferManager = new TransferManager(
            new BasicAWSCredentials(sharedPrefUtil.getAwsSecretKey(), sharedPrefUtil.getAwsAccessKey()));

    // upload thumbnail
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    thumbnail.compress(Bitmap.CompressFormat.JPEG, 80, bos);
    byte[] bitmapData = bos.toByteArray();
    ByteArrayInputStream bs = new ByteArrayInputStream(bitmapData);
    ObjectMetadata meta = new ObjectMetadata();
    meta.setContentLength(bitmapData.length);
    meta.setContentType("image/jpeg");

    Upload upload1 = transferManager.upload(BuildConfig.BUCKET_NAME, // bucket
            guid + "-thumbnail", // name
            bs, meta);//from w w  w. ja  v  a 2s  .  c  o m

    // upload image
    File imageFile = new File(filePath);
    Upload upload2 = transferManager.upload(BuildConfig.BUCKET_NAME, guid, imageFile);

    try {
        upload1.waitForUploadResult();
        upload2.waitForUploadResult();

    } catch (InterruptedException e) {
        e.printStackTrace();
        Log.d(TAG, "upload to s3 error", e);
        return false;
    }

    return true;

}