title: S3 file upload issue on AWS - Spring Boot
body: <p>I have written a piece of code, to upload a file on Amazon S3. It is working fine in my local system. I am able to upload a file and as a response I am getting the file url. But when I try to upload those files to AWS server, they are not getting uploaded, I am getting a 200 response as well, and its showing a rectangle box on postman.  </p>
  
  <p>Can anyone help me to solve this issue? Any help will be appreciated. Thanks!</p>
  
  <pre><code>@Service
  public class AmazonClient {
  
      private AmazonS3 amazonS3;
  
      @Value("${amazonProperties.accessKey}")
      public String accessKey;
  
      @Value("${amazonProperties.secretKey}")
      public String secretKey;
  
      @Value("${amazonProperties.bucketName}")
      public String bucketName;
  
      @Value("${amazonProperties.endpointUrl}")
      public String endpointUrl;
  
      @Value("${amazonProperties.region}")
      public String region;
  
      @PostConstruct
      private void initializeAmazon()
      {
          AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
  
          this.amazonS3 =  AmazonS3ClientBuilder
                  .standard()
                  .withCredentials(new AWSStaticCredentialsProvider(credentials))
                  .withRegion(region)
                  .build();
      }
  
  
      private 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;
      }
  
      private String generateFileName(MultipartFile multiPart)
      {
          return new Date().getTime() + "-" + multiPart.getOriginalFilename().replace(" ", "_");
      }
  
      private void uploadFileTos3bucket(String fileName, File file)
      {
          amazonS3.putObject(new PutObjectRequest(bucketName, fileName, file)
                  .withCannedAcl(CannedAccessControlList.PublicRead));
      }
  
      public String uploadFile(MultipartFile multipartFile) {
  
          String fileUrl = "";
  
          try
          {
              File file = convertMultiPartToFile(multipartFile);
              String fileName = generateFileName(multipartFile);
              fileUrl = endpointUrl + "/" + bucketName + "/" + fileName;
              uploadFileTos3bucket(fileName, file);
              //file.delete();
          }
  
          catch (Exception e)
          {
              e.printStackTrace();
          }
  
          return fileUrl;
      }
  
      public String deleteFileFromS3Bucket(String fileUrl)
      {
          String fileName = fileUrl.substring(fileUrl.lastIndexOf("/") + 1);
          amazonS3.deleteObject(new DeleteObjectRequest(bucketName + "/", fileName));
  
          return "Successfully deleted";
      }
  }
  </code></pre>