简体   繁体   English

如何使用Java从Amazon S3存储桶中使用其名称下载垂直文件

[英]how to download a perticular file using it's name from amazon s3 bucket using java

Actually i have been trying to download the specific file using it's name from amazon s3 bucket folder using java code but i didn't find the worth answer from anyone. 实际上,我一直在尝试使用Java代码从Amazon s3存储桶文件夹中使用其名称下载特定文件,但我没有从任何人那里找到有价值的答案。

package com.simon.amazonbucket;
import java.io.FileOutputStream;
import org.apache.tomcat.util.http.fileupload.IOUtils;
    import com.amazonaws.auth.ClasspathPropertiesFileCredentialsProvider;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.services.s3.model.GetObjectRequest;
import com.amazonaws.services.s3.model.S3Object;
import com.amazonaws.services.s3.model.S3ObjectInputStream;
    public class DownloadingImage {
    public static void main(String[] args) {
        AmazonS3 s3 = new AmazonS3Client(
                new ClasspathPropertiesFileCredentialsProvider());
        try {
/*          GetObjectRequest obj = new GetObjectRequest("simon-aluvala/simonFolder",
    "/" + "");
            S3Object gobj = s3.getObject(obj);
            String name = gobj.getKey();
            S3ObjectInputStream in = gobj.getObjectContent();
            IOUtils.copy(in, new FileOutputStream(
                    "C:/Users/ycs/Desktop/test.doc"));
            System.out.println("downloaded successfully...............");*/

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

How to Get an Object Using the AWS SDK for Java : 如何使用适用于Java的AWS开发工具包获取对象:

  1. Create an instance of the AmazonS3Client class by providing your AWS credentials. 通过提供您的AWS凭证来创建AmazonS3Client类的实例。
  2. Execute one of the AmazonS3Client.getObject() method. 执行AmazonS3Client.getObject()方法之一。 You need to provide the request information, such as bucket name, and key name. 您需要提供请求信息,例如存储桶名称和键名称。 You provide this information by creating an instance of the GetObjectRequest class. 您可以通过创建GetObjectRequest类的实例来提供此信息。
  3. Execute one of the getObjectContent() methods on the object returned to get a stream on the object data and process the response. 在返回的对象上执行getObjectContent()方法之一,以获取对象数据上的流并处理响应。

You can find example here : http://docs.aws.amazon.com/AmazonS3/latest/dev/RetrievingObjectUsingJava.html 您可以在此处找到示例: http : //docs.aws.amazon.com/AmazonS3/latest/dev/RetrievingObjectUsingJava.html

[Disclousre : Bucket Explorer] [Disclousre: Bucket Explorer]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Java在Amazon S3中下载存储桶的密钥 - Key for download bucket in Amazon S3 using Java 如何使用 Java 从 ARN 值解析 Amazon S3 存储桶名称和 object 键? - How to parse an Amazon S3 bucket name and object key from the ARN value by using Java? 使用java filechooser在Amazon s3存储桶中上传多个文件 - Upload multiple file in amazon s3 bucket using java filechooser 如何在Android中使用Java将图像上传到Amazon s3存储桶? - How to upload an image to Amazon s3 bucket using Java in Android? 如何使用Java从amazon s3下载视频文件到特定文件夹 - How to download a video file from amazon s3 to specific folder using Java 使用适用于Amazon S3存储桶的Java SDK下载大量文件 - Download a Large Number of Files Using the Java SDK for Amazon S3 Bucket 我们如何使用 Java SDK 从 S3 存储桶下载没有文件夹的多个文件 - How can we download multiple files without folder from S3 bucket using Java SDK Amazon SES使用Java从S3ObjectInputStream对象读取存储在s3存储桶中的电子邮件 - Amazon SES reading emails stored in an s3 bucket using java from S3ObjectInputStream object 使用API​​在amazon S3存储桶中创建文件夹/上传文件 - creating a folder/uploading a file in amazon S3 bucket using API 如何将图像文件从amazon s3移动到amazon ec2并使用java运行实例 - How to move an image file from amazon s3 to amazon ec2 and run the instance using java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM