I have written AWS Lambda code where I need to store an image in /tmp location of aws lambda. Below is my code:
String fileLocation = "loc1/loc2/";
String imageNameWithoutExt = "image1";
//creating directories first below storing the image
boolean status = new File("/tmp/"+fileLocation).mkdirs();
if(status == true){
File targetFile = File.createTempFile(imageNameWithoutExt,".jpg",new File("/tmp/"+fileLocation));
    FileOutputStream outStream = new FileOutputStream(targetFile);
    outStream.write(buffer);
    outStream.close();
}else{
    System.out.println("unable to create directory inside /tmp/");
}
And in response, it is printing the else statement:
unable to create directory inside /tmp/
What modification I need to make to write and read the files from /tmp location. Any help would be appreciated.
In this line of code, you are not setting the filename:
//write file in /tmp folder of aws Lambda
File targetFile = new File("/tmp/");
I think maybe you aren't showing all your code, because I don't see where the String image1.jpg in the error message would be coming from, but that filename needs to be added to the parameter you are passing the File constructor.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With