Я получаю заданный URL для загрузки на S3. Когда я загружаю код, указанный ниже, я получаю ответ 403 статуса. Я попытался установить общедоступную политику на веб-консоли, но это не помогло. Любые другие идеи о том, как решить проблему? Я также попытался добавить ACL в PublicREADWRITE.
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setRequestMethod("PUT");
OutputStream out = connection.getOutputStream();
// OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream());
//out.write("This text uploaded as an object via presigned URL.");
byte[] boundaryBytes = Files.readAllBytes(Paths.get(edmFile));
out.write(boundaryBytes);
out.close();
// Check the HTTP response code. To complete the upload and make the object available,
// you must interact with the connection object in some way.
int responseCode = connection.getResponseCode();
System.out.println("HTTP response code: " + responseCode);
Предписанный URL:
private URL getUrl(String bucketName, String objectKey) {
String clientRegion = "us-east-1";
java.util.Date expiration = new java.util.Date();
long expTimeMillis = expiration.getTime();
expTimeMillis += 1000 * 60 * 10;
expiration.setTime(expTimeMillis);
AmazonS3 s3Client = AmazonS3ClientBuilder.standard()
.withCredentials(new ProfileCredentialsProvider())
.withRegion(clientRegion)
.build();
GeneratePresignedUrlRequest generatePresignedUrlRequest =
new GeneratePresignedUrlRequest(bucketName, objectKey)
.withMethod(HttpMethod.GET)
.withExpiration(expiration);
URL url = s3Client.generatePresignedUrl(generatePresignedUrlRequest);
System.out.println("Pre-Signed URL: " + url.toString());
return url;
}