-1
我想第一次配置亞馬遜的S3服務,但我無法上傳文件,因爲我得到以下異常(我已經給了用戶完全訪問S3的權限,但我不斷收到此):Amazon S3 - 方法不允許
不允許的方法(服務:亞馬遜S3;狀態代碼:405;錯誤代碼:405不允許的方法; ...)
下面的類我的配置類(爲了安全,密鑰更改爲「xxx」):
public class AmazonConfiguration {
private final String ACCESS_KEY = "xxxxxxxxx";
private final String SECRET_KEY = "xxxxxxxxx";
@Bean
private AmazonS3 amazonS3client() {
//Credenciais de acesso
AWSCredentials credentials = new BasicAWSCredentials(ACCESS_KEY, SECRET_KEY);
AmazonS3 s3Client = new AmazonS3Client(credentials, new ClientConfiguration());
s3Client.setS3ClientOptions(new S3ClientOptions().withPathStyleAccess(true));
s3Client.setEndpoint("http://springmvccasadocodigo.s3-website-us-west-2.amazonaws.com/"); //springmvccasadocodigo.s3-website-sa-east-1.amazonaws.com
return s3Client;
}
}
下節課是我嘗試上傳的文件:
@Component
public class FileServer {
@Autowired
private HttpServletRequest request;
@Autowired
private AmazonS3 s3;
public String writeAmazonS3(String baseFolder, MultipartFile multpartFile) {
try {
s3.putObject("springmvccasadocodigo",
multpartFile.getOriginalFilename(),
multpartFile.getInputStream(), new ObjectMetadata());
return "http://springmvccasadocodigo.s3-website-us-west-2.amazonaws.com/"
+ multpartFile.getOriginalFilename() + "?noAuth=true";
} catch (AmazonClientException | IOException e) {
e.printStackTrace();
throw new RuntimeException();
}
}
}
任何人都知道如何解決?
謝謝你們!