RobinBobin / react-native-google-drive-api-wrapper

This wrapper facilitates the use of the Google Drive API in React Native projects.
110 stars 43 forks source link

Creating a folder using createIfNotExists(...) throws error EISDIR: illegal operation on a directory, read #79

Closed affcue25 closed 1 year ago

affcue25 commented 2 years ago

Hi, I hope you are doing great. I have been trying to create/read my files in a specific folder, and for that I am using createIfNotExists(...) function. As par your document this function check if the folder exist then throw the id of that folder other wise create a new folder and throws its id.. But I am doing the same code as you have given, but its throwing me exception EISDIR: illegal operation on a directory, read

Heres my code:

console.log("folder object",await invoker(async () => (
      await gdrive.files.createIfNotExists(
        {
          q: new ListQueryBuilder()
            .e("name", "TestFolder")
            .and()
            .e("mimeType", MimeTypes.FOLDER)
            .and()
            .in("root", "parents")
        },
       (await gdrive.files.newMetadataOnlyUploader()
          .setRequestBody({
            name: "TestFolder",
            mimeType: MimeTypes.FOLDER,
            parents: ["root"]
          }).execute()).id
        ).catch(e=> {
          console.log("error folder", e);
        })
    )));
Here's my scopes:

`scopes: [
  "https://www.googleapis.com/auth/drive",
  "https://www.googleapis.com/auth/drive.appdata",
  "https://www.googleapis.com/auth/drive.file",
  "https://www.googleapis.com/auth/drive.appfolder",
  'https://www.googleapis.com/auth/drive.metadata',
],` 
RobinBobin commented 2 years ago

As par your document this function check if the folder exist then throw the id of that folder other wise create a new folder and throws its id

Where is it written, that this method:

  1. operates on folders and not files?
  2. throws on success?

Please have a careful look at the prototype of the method in the docs, then compare with your code, and you'll see why it throws.

affcue25 commented 2 years ago

I mean, isnt this function works with query as 1st Param, when query fails to find the folder/file, it execute the 2nd param and returns the result? So, in my case, I am making a query to find folder by name, if it doesnt exist or query fails, then in my 2nd param I am creating a folder... but if folder already exist then it should throw me any result or ID of that folder...

await gdrive.files.createIfNotExists(
      {
        q: new ListQueryBuilder()
          .e("name", "TestFolder")
          .and()
          .e("mimeType", MimeTypes.FOLDER)
          .and()
          .in("root", "parents")
      },
      await (gdrive.files.newMetadataOnlyUploader().setRequestBody({
        name: 'TestFolder',
        mimeType: MimeTypes.FOLDER,
        parents: ['root'],
      }).execute()
RobinBobin commented 2 years ago

Hi, Did you sort it out, or some assistance is still needed?