使用Java从AWS Lambda中的/tmp目录写入文件,然后从中读取文件 [英] Write and then read files from /tmp directory in aws lambda using java
问题描述
我编写了AWS Lambda代码,需要在其中将图像存储在aws lambda的/tmp位置.下面是我的代码:
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/");
}
作为响应,它正在打印else语句:
And in response, it is printing the else statement:
unable to create directory inside /tmp/
我需要进行哪些修改才能从/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/");
我认为您可能没有显示所有代码,因为我看不到错误消息中的字符串image1.jpg
的来源,但是该文件名需要添加到您要传递的参数中File
构造函数.
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.
这篇关于使用Java从AWS Lambda中的/tmp目录写入文件,然后从中读取文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!