在Eclipse IDE中使用Java SDK将对象上载到AWS S3存储桶的问题

时间:2016-11-14 13:41:05

标签: java amazon-web-services amazon-s3 aws-sdk

这是我的代码:

public class UploadObject {

    File samefile;
    String bucketName, bucketLocation, objectKey;

    public UploadObject(){
        System.out.println("Constructor of UploadObject...");
    }

    public void uploadObjectContent(File file) throws Exception{
        samefile = file;
        AWSCredentials credentials = FetchProperties.setCredentials();
        AmazonS3 s3client = new AmazonS3Client(FetchProperties.setCredentials());
        s3client.setEndpoint("https://s3-us-west-2.amazonaws.com");
        s3client.setRegion(Region.getRegion(Regions.US_WEST_2));
        bucketName = "mybucket";
        objectKey = "myobject";
        try {
            if(!(s3client.doesBucketExist(bucketName)))
            {
                s3client.createBucket(new CreateBucketRequest(bucketName));
            }
        }
        catch(Exception e){
            System.out.println("Failure on creating bucket... " + e.getMessage().toString());
        }
        s3client.putObject(new PutObjectRequest(bucketName, objectKey, samefile).withCannedAcl(CannedAccessControlList.PublicRead));
    }
}

我正在尝试将对象上传到我的存储桶,但它显示了我

  

"无法计算MD5哈希:file.txt(系统找不到指定的文件)"。

我不需要在代码上添加MD5哈希值。

0 个答案:

没有答案