[英]Write and then read files from /tmp directory in aws lambda using java
我已經編寫了 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/");
我想也許您沒有顯示所有代碼,因為我沒有看到錯誤消息中的 String image1.jpg
來自哪里,但是需要將該文件名添加到您傳遞File
構造函數的參數中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.