PyDrive icon indicating copy to clipboard operation
PyDrive copied to clipboard

Cannot update file metadata

Open FHowington opened this issue 8 years ago • 6 comments

I am attempting to update the metadata of a file for which I have the fileID. My code is identical to that in the documentation:

                f = drive.CreateFile({'id': filesContained['id']})
                f['title'] = filename
                print(f['title'])
                f.Upload()
                print(f['title'])

where the filesContained['id'] is the correct ID, as I have verified. When I execute this code (in the context of my program), it will print the desired name of my file, but following the upload, the second print statement prints the original name of the file, and indeed the file is seen to not have its title changed in the google drive. What am I doing wrong?

FHowington avatar Jun 05 '17 23:06 FHowington

Thank you for reporting this. Have you checked whether the file's name is changed on Google Drive? The fact that the title value is reset would make some sense if the change was rejected for some reason. Are any errors raised?

If changes are successful remotely and you need a quick fix, you can try the code below:

f = drive.CreateFile({'id': filesContained['id']})
f.FetchMetadata()
print(f['title'])

RNabel avatar Jun 06 '17 16:06 RNabel

Thanks for getting back to me.

There are no errors raised, and the title of the file is not changed remotely. I've pretty much attempted this every way I can think of, with both files and folder, with python 2 and 3, and I'm not having any luck. Is this a problem unique to me?

FHowington avatar Jun 06 '17 21:06 FHowington

I am facing the same trouble

Adarsh-Shrivastava-001 avatar Mar 16 '19 19:03 Adarsh-Shrivastava-001

Facing the same problem. Files get updated but their names remain the same.

mdmmn378 avatar Jan 20 '20 00:01 mdmmn378

I found a fix to this issue, first run a request to the file object, then make the changes.

f = drive.CreateFile({'id': filesContained['id']})  
f_old_title = f['title']
f['title'] = 'New Title'
f.Upload()

swearingbird avatar Dec 07 '20 17:12 swearingbird

I agree with @swearingbird method (tried on Python 3.8, Windows 7, I could rename files and folders). For some reason, the assignation of a new value to f['title'] only works if its old value has been previously read.

Also, @RNabel f.FetchMetadata() code above raises an error, as reported in PyDrive2 fork issues #91 and #103

abubelinha avatar Apr 16 '21 20:04 abubelinha