我编写了 AWS Lambda 代码,我需要将图像存储在 aws lambda 的/tmp 位置。下面是我的代码:
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 语句:
unable to create directory inside /tmp/
我需要做哪些修改才能从/tmp 位置写入和读取文件。任何帮助将不胜感激。
最佳答案
在这行代码中,您没有设置文件名:
//write file in /tmp folder of aws Lambda
File targetFile = new File("/tmp/");
我想也许您没有显示所有代码,因为我看不到错误消息中的字符串 image1.jpg
来自哪里,但需要添加该文件名传递给 File
构造函数的参数。
关于java - 使用java从aws lambda中的/tmp目录写入然后读取文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50509229/