pyicloud icon indicating copy to clipboard operation
pyicloud copied to clipboard

Drive upload fails when not using root directory

Open Prussian1870 opened this issue 4 years ago • 1 comments

Drive upload fails when not using root directory

Windows 10

  • pyiCloud release with the issue (pip show pyicloud): 0.10.2
  • Last working pyiCloud release (if known):
  • Service causing this issue:
  • Python version: 3.85
  • Operating environment (project deps/Docker/Windows/etc.): Windows 10

Traceback/Error logs


Additional information

When trying to upload a file, the DriveService class passes the file_object.name to the iCloud web service. This is OK if the code is running under the root directory but if a full path is supplied to the file open method then the file object name includes the entire path. For example:

with open("c:/myfiletoupload/test.file','rb') as infile: print(infile.name)

The output of this is c:/myfiletoupload/test.file NOT test.file which results in the web service call failing(ObjectNotFoundException: could not find document c: under folder with id A3BF2E31-C19E-494A-95D9-A7774599B537 (NOT_FOUND)). To fix this the DriveService class needs to be modified in the following way:

line 111: "path": {"starting_document_id": folder_id, "path": os.path.basename(file_object.name),}, line 141: request = self.session.post(content_url, files={os.path.basename(file_object.name): file_object})

By using the os.path.basename for the file_object.name the file name only is passed to the web service and will not include the path.

thx

Prussian1870 avatar May 05 '21 20:05 Prussian1870

+1 This worked for me. Thank you. I am using an Ubuntu Server

JosChavz avatar Jan 03 '22 00:01 JosChavz