Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

148
Views
¿Cómo configurar la región para un cliente amazonS3?

Estoy tratando de implementar la carga de archivos en una aplicación web Java. Cuando el usuario carga un archivo a través de la interfaz de usuario, quiero que se almacene en el almacenamiento de amazon amazon s3.

Aquí está mi código para el back-end:

 @PostMapping("/upload-file") public String saveFile(@RequestParam("name") String name, @RequestParam("file")MultipartFile file, RedirectAttributes redirectAttributes){ AWSCredentials credentials = new BasicAWSCredentials("user", "psw"); AmazonS3 s3Client = new AmazonS3Client(credentials); String bucketName = "kfib"; s3Client.createBucket(bucketName); s3Client.setRegion(com.amazonaws.regions.Region.getRegion(Regions.EU_WEST_1)); ObjectMetadata md = new ObjectMetadata(); md.setContentType("application/pdf");

// md.set

 try{ InputStream inputStream = file.getInputStream(); s3Client.putObject(new PutObjectRequest(bucketName, name, inputStream, md).withCannedAcl(CannedAccessControlList.PublicRead)); S3Object s3Object = s3Client.getObject(new GetObjectRequest(bucketName, name)); log.info("Url of the image:\n"); log.info(s3Object.getObjectContent().getHttpRequest().getURI().toString()); }catch(IOException e){ e.printStackTrace(); } log.info("upload called with post method..."); return "redirect:/admin/posts"; }

Puedo subir archivos si los subo a la región predeterminada. Sin embargo, deseo almacenar mis archivos en otro servidor. Tengo un depósito en una región de la UE, si trato de cargar algo allí con el código anterior, obtengo el siguiente código de error:

 com.amazonaws.services.s3.model.AmazonS3Exception: The authorization header is malformed; the region 'us-east-1' is wrong; expecting 'eu-central-1' (Service: Amazon S3; Status Code: 400; Error Code: AuthorizationHeaderMalformed; Request ID: 8EF630B5F0224C4F)

Parece esta línea

 s3Client.setRegion(com.amazonaws.regions.Region.getRegion(Regions.EU_WEST_1));

no tiene ningún efecto. ¿Qué estoy haciendo mal?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Estaba enfrentando el mismo problema, pero lo siguiente funcionó para mí:

 AmazonS3 s3Client = AmazonS3ClientBuilder.standard().withRegion(Regions.US_EAST_1).build();
over 4 years ago · Santiago Trujillo Report

0

Para el acceso al depósito global

puede establecer el indicador withForceGlobalBucketAccessEnabled en verdadero

me gusta

 AmazonS3 s3client = AmazonS3ClientBuilder .standard() .withCredentials(new AWSStaticCredentialsProvider(credentials)) .withForceGlobalBucketAccessEnabled(true) .build();
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!