2

Here is my issue:

  1. I have a folder that I own.
  2. I set permission of X account to my folder as "writer"
  3. X account uploads a file to my folder. (X becomes the owner, I become editor/writer/contributor for that file)
  4. I can move the uploaded file to trash by drive.google.com but not by Drive Api v3

Here is my code:

setTrashedTrue(fileId, callback) {
    authenticate(function (auth) {
        const drive = google.drive({ version: 'v3', auth });
        drive.files.update(
            {
                fileId,
                resource: {
                    trashed: true
                }
            },
            (err, res) => {
                if (err) return console.log('The API returned an error: ' + err);
                callback(res);
            }
        );
    });
}

The resource that I use to write the code above: https://developers.google.com/drive/api/v3/reference/files/update

This throws an error that says:

The API returned an error: Error: The user does not have sufficient permissions for this file.

Apparently you can't delete a file that you don't own. Because it tries to delete it permanently. But I should be able to move it to trash as I can do with the web site of drive.

I printed the details of the uploaded file. This is the related result: (Capabilities are for my account, not the owner of the file.)

  ...
  ownedByMe: false,
  capabilities: {
    ...
    canDelete: false,
    canDownload: true,
    canEdit: true,
    canListChildren: false,
    canModifyContent: true,
    canMoveItemIntoTeamDrive: false,
    canMoveItemOutOfDrive: false,
    canReadRevisions: true,
    canRemoveChildren: false,
    canRename: true,
    canShare: true,
    canTrash: false,      <--------------
    canUntrash: false
  }
  ...

As you see, it tells me that I don't have permission to trash it but in fact I have. So how can I trash a file that doesn't belong to me but shared with me as I am editor?

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
MBDNC
  • 73
  • 6
  • I know the answer is in C# but its basically the same question let me know if you need help converting it to node. – Linda Lawton - DaImTo Jan 14 '20 at 07:55
  • Not sure but I think I got it. So, I suppose even if you use drive app directly to remove that file, it doesn't remove that file. It removes the parent of that file. So file becomes like unassigned file. That's why it makes me think it's being removed. Because even other viewers can't see the file in that folder. But they still have the permission to review that file. Such a strange thing... And I just realized that if someone uploads a file to shared folder, it doesn't uploads directly to drive account of shared folder's owner. It takes up space in drive of person who uploads. – MBDNC Jan 14 '20 at 21:28
  • you may also need to remove the users permission on the file then – Linda Lawton - DaImTo Jan 14 '20 at 21:30
  • So if you remove all permissions from that file, it just disappears and loses it's parent. But still takes space in drive of user who uploaded. There for the uploader person should deal with that for storage management. Not me ':D – MBDNC Jan 14 '20 at 21:31
  • And also I can have management of that file by copying it before deleting permissions. So it becomes mine and covered from deleting. Problem solved. Thanks but I hope people also read here too. – MBDNC Jan 14 '20 at 21:41
  • well you cant remove the owner just it being shared with you. the owner will still have it in their drive – Linda Lawton - DaImTo Jan 15 '20 at 07:23

0 Answers0