title: Upload files into s3 using AWS Lambda function (Java)
body: <p>I am currently making a react native application with aws service. I have few doubts about AWS Service use case and I searched and read about AWS service with my use cases but I didn't get any exact solution.<br>
  <strong>Here is my question,</strong><br>
  I have to store photos and videos into S3 buckets. So I am making a simple mobile application that has access for getting photos and videos from gallery and making a API call to trigger AWS Lambda function (written in Java) to upload those photos and videos into the respective S3 buckets. But my question is, whenever I try to store all those photos and videos into S3 bucket using AWS Lambda function I keep getting no such file or directory exception. I know the reason why I am getting this exception because those photos and Videos are only available in local storage not in AWS cloud (ref <a href="https://stackoverflow.com/questions/35219390/upload-image-into-aws-s3-bucket-using-aws-lambda">Upload Image into AWS S3 bucket using Aws Lambda</a>). So Is there any way to overcome this error? or else I need to get EC2 instance to store all the photos and videos?</p>
  
  <p>My sample Lambda Function code (Upload Image into S3 bucket)</p>
  
  <pre><code>package com.amazonaws.lambda.demo;
  import java.io.File;
  import java.io.IOException; 
  import com.amazonaws.AmazonServiceException;
  import com.amazonaws.SdkClientException;
  import com.amazonaws.auth.AWSCredentials;
  import com.amazonaws.auth.BasicAWSCredentials;
  import com.amazonaws.services.lambda.runtime.Context;
  import com.amazonaws.services.lambda.runtime.RequestHandler;
  import com.amazonaws.services.s3.AmazonS3;
  import com.amazonaws.services.s3.AmazonS3Client;
  import com.amazonaws.services.s3.model.PutObjectRequest;
  import com.amazonaws.services.s3.model.PutObjectResult;
  
  public class LambdaFunctionHandler implements RequestHandler&lt;String, PutObjectResult&gt; {
  @SuppressWarnings("deprecation")
  public PutObjectResult UploadFile(String imageURI) throws IOException {
  
  PutObjectResult resultObj = new PutObjectResult();
  AWSCredentials credentials = new BasicAWSCredentials("Ak", "Sk");
  //String clientRegion = "region";
  String bucketName = "bucket_name";
  String fileObjKeyName = "sample_image_pic.jpg";
  
  try {
      AmazonS3 s3Client = new AmazonS3Client(credentials);
  
      // Upload a file as a new object with ContentType and title specified.
  
      resultObj = s3Client.putObject(new PutObjectRequest(bucketName, fileObjKeyName, new File(imageURI)));
  }
  catch(AmazonServiceException e) {
      // The call was transmitted successfully, but Amazon S3 couldn't process 
      // it, so it returned an error response.
      e.printStackTrace();
  }
  catch(SdkClientException e) {
      // Amazon S3 couldn't be contacted for a response, or the client
      // couldn't parse the response from Amazon S3.
      e.printStackTrace();
  }
  
  return resultObj;
  }
  
  @Override
  public PutObjectResult handleRequest(String imageURI, Context context) {
  
  PutObjectResult result = null;
  try {
      result = UploadFile(imageURI);
  } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
  }
  return result;
  }
  
  }
  </code></pre>
  
  <p>Thanks,</p>