我正在尝试将文件上传到存储桶,但继续获取NoSuchBucket或PermanentRedirect“您尝试访问的存储桶必须使用指定的端点进行寻址”。我很确定我已经正确设置了所有内容,我只是没有正确指定存储桶名称;我看到的所有示例都没有放入实际的存储桶名称。因此,如果我的存储桶被称为example.bucket
且位于EU West 1区域,那么存储桶名称是什么?
File file = getFile();
CognitoCachingCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider(
getApplicationContext(),
"policy_id",
region
);
AmazonS3 s3 = new AmazonS3Client(credentialsProvider);
TransferUtility transferUtility = new TransferUtility(s3, getApplicationContext());
TransferObserver observer = transferUtility.upload(
"example.bucket", // This is what I can't get right
"test_key",
file
);
答案 0 :(得分:0)
File file = getFile();
CognitoCachingCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider(
getApplicationContext(),
"policy_id",
region
);
AmazonS3 s3 = new AmazonS3Client(credentialsProvider);
TransferUtility transferUtility = new TransferUtility(s3, getApplicationContext());
// add this line
s3.setEndpoint("s3.eu-west-1.amazonaws.com"); //it changes based on region name
TransferObserver observer = transferUtility.upload(
"example.bucket", // This is what I can't get right
"test_key",
file
);