0

So I am uploading all files from a dir into S3 using TransferManager and I am able to upload also . But my issue in the same dir file are getting written also. So how do i call that method to write into S3 . Do i have to call that method on fixed interval ? Please suggest what could be the best way to call that method.

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);
        }
    }
Anupam
  • 284
  • 5
  • 21
  • The best thing to do would be to listen to changes in that directory and upload the changes objects to S3 only when a change happens. See https://stackoverflow.com/questions/23452527/watching-a-directory-for-changes-in-java – Matthew Pope Nov 25 '18 at 02:40
  • @MatthewPope yes I am doing that but files are keeps on coming so how do we control the event – Anupam Nov 25 '18 at 03:14
  • 1
    I’m not sure what you’re asking then. Can you try to clarify your question? – Matthew Pope Nov 25 '18 at 03:41
  • @Anupam if I understood correctly, files are continuously getting written on your local directory, you're having a service that keeps listening to the directory, but problem is, file listener is picking files even before completely written by the file creators, is that accurate? please modify the question if not the case – Red Boy Nov 25 '18 at 16:47

1 Answers1

0

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 to abc.jpg.tmp, when files writing completed, then rename it to abc.jpg.

Hope this helps.

Red Boy
  • 5,429
  • 3
  • 28
  • 41