Reputation: 983
Above image shows the structure of my application deployment..
Spring boot application have the below aws configuration.
The application is working on local. I can able to write file to s3 bucket. when i deploy the code on different server as i mentioned above image .Its failed to write s3 bucket Showing below error
Error while uploading the file to S3java.io.FileNotFoundException: sample.txt (Permission denied)"
Note: These servers are in different location.
How can i overcome this issue. I have a solution
Edit 1: 1.I can able to receive request form UI server.but file is not present in the request 2.other get request are working Edit 2
Controller
@PostMapping("/request")
ReturnStatus saveRequest(HttpServletRequest request,
@RequestParam(value = "file", required = true)
MultipartFile uploadedFile) throws InvalidInputException {
AuthDto auth = (AuthDto) request.getAttribute(AUTH_DTO);
return requestService.saveRequest(
new RequestParams( uploadedFile));
}
Service Class Logic
File uploadFile = convertMultiPartToFile(params.getLookUpValues());
s3ClientBuilder.build().putObject(new PutObjectRequest(s3BucketName, fileName, uploadFile));
public static File convertMultiPartToFile(MultipartFile file) throws IOException {
File convFile = new File(file.getOriginalFilename());
FileOutputStream fos = new FileOutputStream(convFile);
fos.write(file.getBytes());
fos.close();
return convFile;
}
Edit 3
create a temp folder inside the UI server tomcat
Once i click on upload file saved to temp and request goes to elastic beanstalk and save the meta data.
How the s3 bucket file upload work?
Need to write any separate script? if yes how its trigger
Pease correct me if am wrong
Upvotes: 0
Views: 956
Reputation: 104178
There are some spring-boot properties for directories used that default to /tmp. Your EB user won't have access to this folder. These settings have allowed us to use multipart upload with Spring Boot in an Elastic Beanstalk environment:
server.tomcat.basedir: ${user.dir}
spring.http.multipart.location: ${user.dir}\
The error is probably coming from this line:
File convFile = new File(file.getOriginalFilename());
You are trying to save a file in base dir, but you don't have access to it. Follow above advice. Alternatively, read this question on how to properly create a tmp folder.
Upvotes: 1