简体   繁体   中英

Amazon S3 AWS upload image to a folder

A quick help here, i wan to achieve an upload of my images to my amazon S3 bucket, i'm able to achieve that with following code.

    s3Client = new AmazonS3Client( new BasicAWSCredentials( getString(R.string.s3_access_key), getString(R.string.s3_secret)));
//params contains file path
                        //PutObjectRequest por = new PutObjectRequest( getString(R.string.s3_bucket), params[0].getName(), params[0]);  
                        PutObjectRequest por = new PutObjectRequest( getString(R.string.s3_bucket), params[0].getName(), params[0]);
                        s3Client.putObject(por);

                        ResponseHeaderOverrides override = new ResponseHeaderOverrides();
                        override.setContentType( "image/jpeg" );
                        urlRequest = new GeneratePresignedUrlRequest( getString(R.string.s3_bucket), params[0].getName() );
                        urlRequest.setExpiration( new Date( System.currentTimeMillis() + 3600000 ) );  // Added an hour's worth of milliseconds to the current time.
                        urlRequest.setResponseHeaders( override );

There is a folder in my bucket I'm not able to upload images to that folder.

what i tried for uploading images to folder into bucket is this

PutObjectRequest por = new PutObjectRequest( getString(R.string.s3_bucket), params[0].getName(), params[0]).withKey("testmorya/");
                    s3Client.putObject(por);

BUCKET NAME : morya FOLDER NAME : testmorya

Help appreciated

It is all about how you structure your key. To put "filea" into "folderb", just name the key of the object as "folderb/filea".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM