AmazonS3 multipart uploading

475 views Asked by At

I have used multi part uploading for uploading image to Amazon S3 as mentioned in documentation.

But then the files uploaded can be access directly without access key or anything. Tested using the remote URL which is got from response for a particular file. Is there any way to restrict access to uploaded file? Also is there a way to change the upload URL here, If I want to add a folder and the the file?

2

There are 2 answers

6
Kumar Panchal On BEST ANSWER

Yes you can create folder by using below method.

     AmazonS3 amazons3Client = new AmazonS3Client(new ProfileCredentialsProvider());
     public void createFolder(String bucketName, String folderName)
        {
            try
            {

                        ObjectMetadata objectMetaData = new ObjectMetadata();
                        objectMetaData.setContentLength(0);
                        InputStream emptyContent = new ByteArrayInputStream(new byte[0]);
                        amazons3Client.putObject(new PutObjectRequest(bucketName, folderName + "/", emptyContent, objectMetaData));
            }
            catch (Exception exception)
            {
                LOGGER.error("Exception In Create Folder", exception);
            }

        }

Access rights you can use policy and it will apply on specific to your bucket,Please go through below link You can allow specific IP to access. http://docs.aws.amazon.com/AmazonS3/latest/dev/example-bucket-policies.html

2
Vardaan Sharma On

For managing access to your file, you will need to follow the instructions here: http://docs.aws.amazon.com/AmazonS3/latest/dev/s3-access-control.html

It is covered in more detail here: http://docs.aws.amazon.com/AmazonS3/latest/dev/intro-managing-access-s3-resources.html