Ich entwickle eine Produktregistrierungs-API im Spring-Boot und sende in meiner Post-Methode ein Bild-Upload über Multipart/Form-Data, zusammen mit einem JSON mit dem DTO meines Produkts. Wie Sie sehen können: < /p>
@RestController
@CrossOrigin(origins = "*", maxAge = 3600)
@RequestMapping("/product")
public class ProductController {
final ProductService productService;
final CategoryService categoryService;
final ProductMapper productMapper;
final S3Client s3Client;
private final String BUCKET_NAME = "awstockproducts" + System.currentTimeMillis();
public ProductController(ProductService productService, ProductMapper productMapper, CategoryService categoryService, S3Client s3Client) {
this.productService = productService;
this.productMapper = productMapper;
this.categoryService = categoryService;
this.s3Client = s3Client;
}
@PostMapping(value = "/", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ResponseEntity saveProduct (@RequestParam("productDto") String jsonString, @RequestParam("file")MultipartFile file) {
try {
ObjectMapper objectMapper = new ObjectMapper();
ProductDto productDto = objectMapper.readValue(jsonString, ProductDto.class);
if (productService.existsByProduct(productDto.getProduct())) {
return ResponseEntity.status(HttpStatus.CONFLICT).body("Product already exists!");
}
ProductModel productModel = productMapper.toProductModel(productDto);
CategoryModel categoryModel = categoryService.findById(productDto.getProductCategory().getCategory_id())
.orElseThrow(() -> new RuntimeException("Category not found"));
productModel.setProductCategory(categoryModel);
String fileName = "/products/images/" + UUID.randomUUID().toString() + "-" + file.getOriginalFilename();
s3Client.putObject(PutObjectRequest
.builder()
.bucket(BUCKET_NAME)
.key(fileName)
.build(),
software.amazon.awssdk.core.sync.RequestBody.fromString("Testing java sdk"));
return ResponseEntity.status(HttpStatus.CREATED).body(productService.save(productModel));
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.CONFLICT).body(e);
}
}
< /code>
Das Problem ist, dass ich Probleme habe, die Anfrage von meinem Postman zu machen < /p>
"localizedMessage": "The specified bucket does not exist (Service: S3, Status Code: 404, Request ID: ZZ27F9CNNTG2RTPR, Extended Request ID:
< /code>
Trotz der Nachricht, überprüft Amazon AWS Ich kann sehen, dass mein Eimer tatsächlich existiert und denselben Namen hat wie der, den ich in meiner Anwendung konfiguriert habe. Dies ist AmazonConfig < /p>
package com.api.business_manager_api.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.s3.S3Client;
@Configuration
public class AmazonConfig {
private final String AWS_REGION = "us-east-1";
private final String BUCKET_NAME = "productstockimages";
@Value("${aws.accessKeyId}")
private String accessKeyId;
@Value("${aws.secretAccessKey}")
private String secretAccessKey;
@Bean
public S3Client s3Client() {
AwsBasicCredentials awsCreds = AwsBasicCredentials.create(accessKeyId, secretAccessKey);
return S3Client.builder()
.region(Region.of(AWS_REGION))
.credentialsProvider(StaticCredentialsProvider.create(awsCreds))
.build();
}
}
In meinem SecretKey und in meinem AccessKey habe ich in Eigenschaften mit den Schlüssel meines autorisierten IAM -Benutzers von der Amazon AWS -Konsole konfiguriert.
Ich entwickle eine Produktregistrierungs-API im Spring-Boot und sende in meiner Post-Methode ein Bild-Upload über Multipart/Form-Data, zusammen mit einem JSON mit dem DTO meines Produkts. Wie Sie sehen können: < /p> [code]@RestController @CrossOrigin(origins = "*", maxAge = 3600) @RequestMapping("/product") public class ProductController { final ProductService productService; final CategoryService categoryService; final ProductMapper productMapper; final S3Client s3Client;
private final String BUCKET_NAME = "awstockproducts" + System.currentTimeMillis();
< /code> Das Problem ist, dass ich Probleme habe, die Anfrage von meinem Postman zu machen < /p> "localizedMessage": "The specified bucket does not exist (Service: S3, Status Code: 404, Request ID: ZZ27F9CNNTG2RTPR, Extended Request ID: < /code> Trotz der Nachricht, überprüft Amazon AWS Ich kann sehen, dass mein Eimer tatsächlich existiert und denselben Namen hat wie der, den ich in meiner Anwendung konfiguriert habe. Dies ist AmazonConfig < /p> package com.api.business_manager_api.Config; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import software.amazon.awssdk.auth.credentials.AwsBasicCredentials; import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider; import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.s3.S3Client;
@Configuration public class AmazonConfig { private final String AWS_REGION = "us-east-1"; private final String BUCKET_NAME = "productstockimages";
[/code] In meinem SecretKey und in meinem AccessKey habe ich in Eigenschaften mit den Schlüssel meines autorisierten IAM -Benutzers von der Amazon AWS -Konsole konfiguriert.
Es tritt der Fehler auf, dass die aktuelle Anfrage keine mehrteilige Anfrage ist.
2024-12-21T15:33:28.898+05:30 ERROR 3312 --- o.a.c.c.C.[.[. . : Servlet.service()
for Servlet im Kontext mit Pfad []...
Ich habe mir die meisten Codeproben angesehen, die auf diesem Problem auf dem Stack -Überlauf basieren, aber ich kann die Anfrage immer noch nicht zur Arbeit bringen. Ich erhalte immer wieder diesen...
Mit Amazon Products API möchte ich erste Produkte in Kategorien DVD und Amazon Instant Video mit Keyword My Movie gefunden.$amazonEcs = new AmazonECS(AWS_API_KEY, AWS_API_SECRET_KEY, 'com',...
Ich arbeite an AWS Lambda im Spring Boot-Framework.
Ich habe den Code aus dem folgenden Link verwendet, um Zertifikate aus Dateien zu laden, weil beim Erstellen des PKIX-Pfads ein Fehler aufgetreten...
Ich arbeite an AWS Lambda im Spring Boot-Framework.
Ich habe den Code aus dem folgenden Link verwendet, um Zertifikate aus Dateien zu laden, weil beim Erstellen des PKIX-Pfads ein Fehler aufgetreten...