FileSystem icon indicating copy to clipboard operation
FileSystem copied to clipboard

Google Drive is storing the file in the root, ignoring the paths

Open kelter-antunes opened this issue 1 year ago • 6 comments

Hi, It seems that GDrive adapter is not following the paths like azure blob and Amazon s3 are doing it. For those two everything is working as expected but not for GDrive.

// Adapter settings
string adapterPrefix = "gdrive";
string rootPath = "/demofolder";

// File system path settings
string path = "/from/demo/app";
string fileName = "example.env";
string localFilePath = @"C:\Users\XXXXXX\Downloads\example.env";

...

// Create Google Drive adapter
var googleDriveAdapter = new GoogleDriveAdapter(adapterPrefix, rootPath, driveService);

// Create file system with Google Drive adapter
googleDriveFileSystem = new FileSystem(new List<IAdapter> { googleDriveAdapter });

...

// Construct virtual path
virtualPath = $"{adapterPrefix}://{path}{fileName}"; // =  "gdrive://from/demo/app/example.env"

// Write file to Google Drive
googleDriveFileSystem.WriteFile(virtualPath, binaryData, true);

// Retrieve file from Google Drive
var existingFile = googleDriveFileSystem.GetFile(virtualPath);

The file is stored in the GDrive root: image

And then when trying to get the file for the same virtualPath I get the following exception:

"File 'demofolder/from/demo/app/example.env' not found in adapter with prefix 'gdrive'."

Is it me that I'm doing anything wrong?

kelter-antunes avatar Jul 18 '24 13:07 kelter-antunes

@kelter-antunes could you check what would happen if you add a forward slash between the path and filename?

virtualPath = $"{adapterPrefix}://{path}/{fileName}";

mvdgun avatar Jul 18 '24 16:07 mvdgun

image

Makes it double slash, and then there's an exception when trying to save the file: GoogleApiException: The service drive has thrown an exception. HttpStatusCode is InternalServerError. Internal Error

kelter-antunes avatar Jul 18 '24 16:07 kelter-antunes

@kelter-antunes, after some investigation, it appears that the Google Drive adapter does not implicitly handle creating folders in a path if they do not exist. A current workaround is to manually create the necessary folders before storing files. I will leave this ticket open to address implicit folder creation in future versions.

mvdgun avatar Jul 18 '24 17:07 mvdgun

Yes, I can confirm that. I tested it myself, and if the full path doesn't exist, it places the file in the root. I tried it with just one or two folders from the path, and if the full path doesn't exist, it always places the file in the root. Thank you for your quick response.

kelter-antunes avatar Jul 19 '24 08:07 kelter-antunes

@mvdgun I just wanted to share some more thoughts on this. I'm also looking to store files on Shared Drives, and it's getting complicated since we can't have a full path for a Shared Drive (at least to my knowledge). In the end, Google Drive, for better or worse, only requires a Folder ID to place the file, whether it's on our local drive or a Shared Drive.

I can't think of the best solution to maintain the same generic actions across all adapters. However, knowing this, it would be nice if, for the Google Drive adapter, we could pass only a Folder ID instead of a root + virtual path or something similar.

kelter-antunes avatar Jul 19 '24 09:07 kelter-antunes

@kelter-antunes The Google Drive adapter has a lot of custom directory traversing to emulate a file system like behavior (like you said with the parent folder ID). I would suspect that Shared drives would work the same as a regular Google Drive though. I don't have a lot of free time on my hands currently so I cannot quickly test this one out.

mvdgun avatar Jul 19 '24 14:07 mvdgun