是否有任何官方的java.nio.file实现AWS?
我为GoogleCloudStorage 这里找到了一个,AWS和Azure也需要类似的。
发布于 2019-02-25 20:00:12
您可以尝试使用亚马逊AWS S3 FileSystem提供者JSR-203 for Java 7 (NIO2)
从Maven Central下载
<dependency>
<groupId>com.upplication</groupId>
<artifactId>s3fs</artifactId>
<version>2.2.2</version>
</dependency>在您的META-INF/services/java.nio.file.spi.FileSystemProvider中添加一个新行(如果还没有创建),如下所示: com.upplication.s3fs.S3FileSystemProvider。
使用此代码创建fileSystem并将其设置为具体的端点.
FileSystems.newFileSystem("s3:///", new HashMap<String,Object>(), Thread.currentThread().getContextClassLoader());如何在Apache 中使用
public FileSystemFactory createFileSystemFactory(String bucketName) throws IOException, URISyntaxException {
FileSystem fileSystem = FileSystems.newFileSystem(new URI("s3:///"), env, Thread.currentThread().getContextClassLoader());
String bucketPath = fileSystem.getPath("/" + bucketName);
return new VirtualFileSystemFactory(bucketPath);
}如何在Spring中使用
添加到类路径并配置:
@Configuration
public class AwsConfig {
@Value("${upplication.aws.accessKey}")
private String accessKey;
@Value("${upplication.aws.secretKey}")
private String secretKey;
@Bean
public FileSystem s3FileSystem() throws IOException {
Map<String, String> env = new HashMap<>();
env.put(com.upplication.s3fs.AmazonS3Factory.ACCESS_KEY, accessKey);
env.put(com.upplication.s3fs.AmazonS3Factory.SECRET_KEY, secretKey);
return FileSystems.newFileSystem(URI.create("s3:///"), env, Thread.currentThread().getContextClassLoader());
}
}注入任何弹簧组件:
@Autowired
private FileSystem s3FileSystem;发布于 2022-11-28 18:10:53
使用异步预读缓冲的FileSystemProvider SPI的一个实现是可用的来自github和来自Maven Central。这个库目前不支持向S3写入,但是可以添加它。
您可以使用以下方法将其包含在Maven项目中:
<dependency>
<groupId>software.amazon.nio.s3</groupId>
<artifactId>aws-java-nio-spi-for-s3</artifactId>
<version>1.1.1</version>
</dependency>或者,您可以将JAR文件放在类路径上,JVM将使用s3方案将所有URI路由到该提供程序。
https://stackoverflow.com/questions/41113119
复制相似问题