javaandroidamazon-web-servicesamazon-s3uploading

AmazonS3 multipart uploading


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?


Solution

  • 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