简体   繁体   English

如何使用 Java 从 ARN 值解析 Amazon S3 存储桶名称和 object 键?

[英]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:

  • arn:aws:s3 arn:aws:s3
  • bucketmay10002/book.pdf bucketmay10002/book.pdf
  • bucketmay10002桶五月10002
  • book.pdf book.pdf

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.

相关问题 如何使用Java从Amazon S3存储桶中使用其名称下载垂直文件 - how to download a perticular file using it's name from amazon s3 bucket using java 使用Java在Amazon S3中下载存储桶的密钥 - Key for download bucket in Amazon S3 using Java Amazon SES使用Java从S3ObjectInputStream对象读取存储在s3存储桶中的电子邮件 - Amazon SES reading emails stored in an s3 bucket using java from S3ObjectInputStream object 将 Java 对象存储到 Amazon S3 存储桶 - Store Java object to Amazon S3 bucket 使用 Java (Amazon S3) 将 all.txt 文件从一个 object 复制到另一个但在同一个存储桶中 - Copy all .txt files from one object to another but in the same bucket using Java (Amazon S3) 如何在Android中使用Java将图像上传到Amazon s3存储桶? - How to upload an image to Amazon s3 bucket using Java in Android? 如何从Java中的bucket.s3.amazonaws.com/key更改s3.amazonaws.com/bucket/key之类的Amazon S3文件URL? - How to Change Amazon S3 file URL Like s3.amazonaws.com/bucket/key from bucket.s3.amazonaws.com/key in Java? Amazon S3:`key`是要上传到存储桶而不是文件的对象 - Amazon S3: `key` is the object being uploaded to bucket instead of the file 当密钥使用文件夹结构定义时,我们如何从 AWS s3 存储桶中获取 Object? Java - How can we get the Object from the AWS s3 bucket when the key is defined with folder structure? Java 使用java filechooser在Amazon s3存储桶中上传多个文件 - Upload multiple file in amazon s3 bucket using java filechooser
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM