java - 使用 java 从 aws lambda 中的 /tmp 目录写入然后读取文件
问题描述
我已经编写了 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
构造函数的参数中。
推荐阅读
- c - 在 C 中对不同类型结构的数组使用搜索函数
- python - 显示 30 个变量和 10000 个数据点的 3-D 曲面图
- asp.net - 在一个域下托管多个 Asp.net Core 项目
- android - 如何设置发送到 NotificationHub 的推送通知的高优先级
- bots - 功能删除命令有问题,请阅读代码前的文字。谢谢
- java - Selenium - Java - 如何断言/验证页面上的所有链接是否正常工作,获取标题并根据预期标题进行验证
- python - 每当在 Flask App 中请求静态文件时捕获请求标头
- regex - 使用 Regex Elastic Query 未识别未识别文字撇号的所有实例
- python - 如何使用人体姿态估计生成骨架视图?
- android - 在片段中添加和实现微调器