【问题标题】:How to get file from a S3 link - java如何从 S3 链接获取文件 - java
【发布时间】:2016-12-09 16:53:14
【问题描述】:

如何在 Java 中从 Amazon 文件路径获取文件。它总是返回(文件名、目录名或卷标语法不正确)错误。如果我提供本地路径,它会完美运行。这是我的代码

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();
                }
            }

错误:java.io.FileNotFoundException: https:\mydomain:8080\S3DOC\?filename=\folder\DEV\Portal\sample.doc(文件名、目录名或卷标语法不正确)

【问题讨论】:

    标签: java amazon-s3


    【解决方案1】:

    s3 路径如:s3://bucket/key

    你可以使用

     AmazonS3Client.getObject(String bucketName, String key);
    

    获取一个S3Object,然后获取InputStream。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-26
      相关资源
      最近更新 更多