[英]How to parse an Amazon S3 bucket name and object key from the ARN value by using Java?
I am working with Amazon S3 and I need to parse the Amazon S3 bucket name and object key from the object ARN by using Java.我正在使用 Amazon S3,我需要使用 Java 从 object ARN 解析 Amazon S3 存储桶名称和 object 密钥。 Is there any built-in library for it?有没有内置的库呢? if not can you help me with the java code for it.如果不能,你能帮我用 java 代码吗?
The Amazon S3 API does not have an API method for this. Amazon S3 API 没有为此的 API 方法。 You can use Java logic to obtain the bucket name and object name from an Object ARN.您可以使用 Java 逻辑从 Object ARN 中获取存储桶名称和 object 名称。 Here is your solution.这是您的解决方案。
String arn = "arn:aws:s3:::bucketmay10002/book.pdf";
String bucketObject = "";
String[] value1 = arn.split(":::");
for (String t : value1){
bucketObject = t ;
System.out.println(bucketObject);
}
String[] value3 = bucketObject.split("/");
for (String t : value3)
System.out.println(t);
}
Output: Output:
As you can see, you get both the bucket name and object name from the given object ARN.如您所见,您从给定的 object ARN 中同时获得了存储桶名称和 object 名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.