Example usage for com.amazonaws.services.s3.model PutObjectRequest withAccessControlList

List of usage examples for com.amazonaws.services.s3.model PutObjectRequest withAccessControlList

Introduction

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

Prototype

@Override
    @SuppressWarnings("unchecked")
    public PutObjectRequest withAccessControlList(AccessControlList accessControlList) 

Source Link

Usage

From source file:com.wowza.wms.plugin.s3upload.ModuleS3Upload.java

License:Open Source License

private void resumeUploads() {
    if (!resumeUploads) {
        transferManager.abortMultipartUploads(bucketName, new Date());
        return;/*from w w w.  j a  v  a  2  s  .  c o  m*/
    }

    File storageDir = new File(appInstance.getStreamStorageDir());
    File[] files = storageDir.listFiles(new FilenameFilter() {

        @Override
        public boolean accept(File dir, String name) {
            return name.toLowerCase().endsWith(".upload");
        }
    });

    for (File file : files) {
        String mediaName = file.getPath().replace(storageDir.getPath(), "");
        if (mediaName.startsWith("/"))
            mediaName = mediaName.substring(1);

        mediaName = mediaName.substring(0, mediaName.indexOf(".upload"));
        Upload upload = null;
        FileInputStream fis = null;
        try {
            if (file.length() == 0) {
                File mediaFile = new File(storageDir, mediaName);
                if (mediaFile.exists()) {
                    // In order to support setting ACL permissions for the file upload, we will wrap the upload properties in a PutObjectRequest
                    PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, mediaName, file);

                    // If the user has specified ACL properties, setup the putObjectRequest with the acl permissions generated
                    if (acl != null) {
                        putObjectRequest.withAccessControlList(acl);
                    }

                    upload = transferManager.upload(putObjectRequest);
                } else {
                    file.delete();
                }
            } else {
                fis = new FileInputStream(file);
                // Deserialize PersistableUpload information from disk.
                PersistableUpload persistableUpload = PersistableTransfer.deserializeFrom(fis);
                upload = transferManager.resumeUpload(persistableUpload);
            }
            if (upload != null)
                upload.addProgressListener(new ProgressListener(mediaName));
        } catch (Exception e) {
            logger.error(MODULE_NAME + ".resumeUploads error resuming upload: [" + appInstance.getContextStr()
                    + "/" + file.getName() + "]", e);
        } finally {
            if (fis != null) {
                try {
                    fis.close();
                } catch (IOException e) {
                }
            }
        }
    }
}