Putting object to S3 using java but didn't see any object from the console

Laodao :

I have tried the following code to put a string into the S3. I saw the folder was created under the bucket but didn't see any object in the folder. What am I missing?

            String SUFIX = "/";

            try {
                s3client.putObject(bucketName, today.toString() + SUFFIX + source + SUFFIX, "abc");
            } catch (Exception e) {
                e.printStackTrace();
            }

I don't think it is a permission issue, cause I have those folders created by above code and there is no exception caught by the try-catch also. Please help. Thanks

Random Guy :

From Amazon S3 folders documentation:

The Amazon S3 console treats all objects that have a forward slash (/) character as the last (trailing) character in the key name as a folder, for example examplekeyname/. You can't upload an object that has a key name with a trailing / character using the Amazon S3 console.

However, you can upload objects that are named with a trailing / with the Amazon S3 API by using the AWS CLI, AWS SDKs, or REST API.

An object that is named with a trailing "/" appears as a folder in the Amazon S3 console.

So, in your case, removing trailing slash should do the work:

String SUFIX = "/";
try {
    s3client.putObject(bucketName, today.toString() + SUFFIX + source, "abc");
} catch (Exception e) {
    e.printStackTrace();
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=335406&siteId=1