AWS的java.nio.file实现
AWS是否有任何官方的AWS的java.nio.file实现,java,amazon-s3,java.nio.file,s3fs-nio,Java,Amazon S3,Java.nio.file,S3fs Nio,AWS是否有任何官方的java.nio.file实现 我为GoogleCloudStorage找到了一个,并且需要类似的AWS和Azure您可以尝试使用 从Maven Central下载 <dependency> <groupId>com.upplication</groupId> <artifactId>s3fs</artifactId> <version>2.2.2</version>
java.nio.file
实现
我为GoogleCloudStorage
找到了一个,并且需要类似的AWS
和Azure
您可以尝试使用
从Maven Central下载
<dependency>
<groupId>com.upplication</groupId>
<artifactId>s3fs</artifactId>
<version>2.2.2</version>
</dependency>
如何在春季使用
添加到类路径并配置:
@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());
}
}
Azure似乎没有正式的
java.nio.file
实现。您想使用Java NIO的云实现做什么?我需要它作为不同类型存储的抽象。我知道了,但什么都没有。唯一的方法是定义自己的API来实现不同类型存储的包装器。我还希望抽象出非标准的AWS S3 API,并以某种方式将其隐藏在“卷服务”或Java NIO类后面
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;