You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to create an empty folder in an AWS S3 bucket using the VFS-S3 plugin for the Apache VFS library. Below is a code snippet demonstrating my approach:
FileSystemManager fileSystemManager = VFS.getManager();
// 'root-folder' already exists in 'test-bucket' in the 'eu-central-1' region, as part of the initial configuration
String baseURI = "s3://test-bucket.s3-eu-central-1.amazonaws.com/root-folder";
FileObject rootFolderFileObject = fileSystemManager.resolveFile(baseURI, null);
// Here, I attempt to create an empty 'child-folder' within 'root-folder'
FileObject childFolderFileObject = rootFolderFileObject.resolveFile("child-folder");
childFolderFileObject.createFolder();
However, this code throws the following error:
[ERROR] [stderr] org.apache.commons.vfs2.FileSystemException: Could not create folder "S3FileName{endpoint='s3.eu-central-1.amazonaws.com', urlPrefix='null', pathPrefix='test-bucket', bucket='test-bucket', signingRegion='eu-central-1', platformFeatures=PlatformFeaturesImpl{defaultAllowForOwner=true, allowDenyForOwner=true, supportsServerSideEncryption=true, supportsAuthorizedGroup=true}, accessKey='null', secretKey='null'}".
[ERROR] [stderr] at deployment.planon.ear//com.github.vfss3.AbstractFileObject.createFolder(AbstractFileObject.java:386)
[ERROR] [stderr] at deployment.planon.ear//com.github.vfss3.S3FileObject.createFolder(S3FileObject.java:38)
...
[ERROR] [stderr] Caused by: org.apache.commons.vfs2.FileSystemException: Could not create folder "S3FileName{endpoint='s3.eu-central-1.amazonaws.com', urlPrefix='null', pathPrefix='test-bucket', bucket='test-bucket', signingRegion='eu-central-1', platformFeatures=PlatformFeaturesImpl{defaultAllowForOwner=true, allowDenyForOwner=true, supportsServerSideEncryption=true, supportsAuthorizedGroup=true}, accessKey='null', secretKey='null'}" because it already exists and is a file.
[ERROR] [stderr] at deployment.planon.ear//com.github.vfss3.AbstractFileObject.createFolder(AbstractFileObject.java:375)
Interestingly, when I try to upload a file into a non-existent folder, the library successfully creates the missing folder and uploads the file into it. Here’s the relevant code:
// Create a temporary source file
File tempSourceFile = File.createTempFile("tempSourceFile", ".txt");
tempSourceFile.deleteOnExit();
try (FileWriter fileWriter = new FileWriter(tempSourceFile)) {
fileWriter.write("This is test data.");
}
FileSystemManager fileSystemManager = VFS.getManager();
// 'root-folder' already exists in 'test-bucket' in the 'eu-central-1' region
String baseURI = "s3://test-bucket.s3-eu-central-1.amazonaws.com/root-folder";
FileObject rootFolderFileObject = fileSystemManager.resolveFile(baseURI, null);
// Attempt to upload 'child-file.txt' to a non-existent 'child-folder' within 'root-folder'
FileObject childFileObject = rootFolderFileObject.resolveFile("child-folder/child-file.txt");
childFileObject.createFile();
try (InputStream sourceInputStream = new FileInputStream(tempSourceFile);
OutputStream destinationOutputStream = childFileObject.getContent().getOutputStream()) {
byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = sourceInputStream.read(buffer)) != -1) {
destinationOutputStream.write(buffer, 0, bytesRead);
}
} catch (IOException ex) {
ex.printStackTrace();
}
This code successfully creates the child-folder within root-folder and uploads child-file.txt into it.
It appears that creating an empty folder directly is not possible, while creating a folder through file upload works as expected. Could this be a bug or a limitation of the VFS-S3 plugin? Any insights into why creating an empty folder fails but implicitly creating one with a file succeeds would be greatly appreciated.
The text was updated successfully, but these errors were encountered:
I am trying to create an empty folder in an AWS S3 bucket using the VFS-S3 plugin for the Apache VFS library. Below is a code snippet demonstrating my approach:
However, this code throws the following error:
Interestingly, when I try to upload a file into a non-existent folder, the library successfully creates the missing folder and uploads the file into it. Here’s the relevant code:
This code successfully creates the child-folder within root-folder and uploads child-file.txt into it.
It appears that creating an empty folder directly is not possible, while creating a folder through file upload works as expected. Could this be a bug or a limitation of the VFS-S3 plugin? Any insights into why creating an empty folder fails but implicitly creating one with a file succeeds would be greatly appreciated.
The text was updated successfully, but these errors were encountered: