有官方的java.nio.file
实施方案AWS
吗?
我在GoogleCloudStorage
这里找到了一个,并且需要与AWS
和类似Azure
。
您可以尝试使用适用于Java 7(NIO2)的Amazon AWS S3文件系统提供程序JSR-203
从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。
使用此代码创建文件系统并设置为具体端点。
FileSystems.newFileSystem("s3:///", new HashMap<String,Object>(), Thread.currentThread().getContextClassLoader());
如何在Apache MINA中使用
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);
}
春季如何使用
添加到类路径并配置:
@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;
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句