这是我的代码:
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哈希值。