Hari
Hari

Reputation: 297

How to get file from a S3 link - java

How to get file from Amazon file path in Java. It always returns (The filename, directory name, or volume label syntax is incorrect) error. If I give local path, It works perfectly. Here is my code

FileInputStream fis;
            String filePath = "https://mydomain:8080/S3DOC/?filename=/folder/DEV/Portal/sample.doc";
            if(FilePath.substring(FilePath.length() -1).equals("x")){ //is a docx
                System.out.println("docx");
            try {
                fis = new FileInputStream(new File(FilePath));
                XWPFDocument doc = new XWPFDocument(fis);
                XWPFWordExtractor extract = new XWPFWordExtractor(doc);
                System.out.println(extract.getText());
            } catch (IOException e) {

                e.printStackTrace();
            }
            } else { //is not a docx
                System.out.println("doc");
                try {
                    fis = new FileInputStream(new File(FilePath));
                    HWPFDocument doc = new HWPFDocument(fis);
                    WordExtractor extractor = new WordExtractor(doc);
                    System.out.println(extractor.getText());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

Error : java.io.FileNotFoundException: https:\mydomain:8080\S3DOC\?filename=\folder\DEV\Portal\sample.doc (The filename, directory name, or volume label syntax is incorrect)

Upvotes: 1

Views: 5052

Answers (1)

Tom Grylls
Tom Grylls

Reputation: 121

s3 path like : s3://bucket/key

You can use

 AmazonS3Client.getObject(String bucketName, String key);

Get a S3Object,and then get InputStream.

Upvotes: 1

Related Questions