使用 java 在 aws lambda 中写入并读取 /tmp 目录中的文件

2024-06-28

我编写了 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构造函数。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 java 在 aws lambda 中写入并读取 /tmp 目录中的文件 的相关文章

随机推荐