java - 当文件继续写入目录时如何将目录中的文件上传到S3
问题描述
所以我将所有文件从一个目录上传到 S3 使用TransferManager
,我也可以上传。但是我在同一个目录文件中的问题也被写入了。那么我如何调用该方法写入 S3 。我必须以固定的时间间隔调用该方法吗?请建议调用该方法的最佳方法。
public void uploadDir(Path strFile,String strFileName){
ArrayList<File> files = new ArrayList<File>();
for (Path path : strFile) {
files.add(new File(path.toString()));
}
TransferManager xfer_mgr = TransferManagerBuilder.standard().build();
try {
MultipleFileUpload xfer = xfer_mgr.uploadFileList(bucketName,strFileName, new File("."), files);
//XferMgrProgress.showTransferProgress(xfer);
//XferMgrProgress.waitForCompletion(xfer);
} catch (AmazonServiceException e) {
System.err.println(e.getErrorMessage());
System.exit(1);
}
}
解决方案
Couple of solutions, you could try any, based on your need.
Solution 1:- For scanrio like your, instead of time interval, you should be using fileAge
.
FileAge:when the file was last modified, this common concept used by file Poller either local directory or remote directory.
So think like your files takes max. 20 seconds in writing, then only pull files older then 20s or more.
Solution 2:-
Other way is ask your clients, the program generating files to use some extension say .tmp, when file writing completed, ask them to convert it to actual file extension and modify your program to skip files with extension .tmp. e.g While writing
abc.jpg
toabc.jpg.tmp
, when files writing completed, then rename it toabc.jpg
.
Hope this helps.
推荐阅读
- javascript - window.onmousemove 和 document.onmousemove 不捕获 iframe 事件
- android - 无法使用来自 java 的 varargs 调用 kotlin 函数
- postgresql - PostgreSQL 在恢复时的 pg_restore 错误
- javascript - PHP错误的数据库编辑
- asp.net - iis 8.0 上的 502 bad gateway 间歇性使用 ARR
- python - 为什么我的图像卷积函数这么慢?
- javascript - 如何用 jest 模拟或测试异步 cb 函数?
- php - Ubuntu 16.04 流浪者盒子。PHP 5.6 快速cgi。我在页面上收到一个通用的 500 错误,但在任何地方都没有日志
- excel - VBA 表格调整大小正在替换下面的内容
- sql - 如何优化数据库连接