Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drive upload fails when not using root directory #337

Open
Prussian1870 opened this issue May 5, 2021 · 1 comment · May be fixed by #449
Open

Drive upload fails when not using root directory #337

Prussian1870 opened this issue May 5, 2021 · 1 comment · May be fixed by #449

Comments

@Prussian1870
Copy link

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

@JosChavz
Copy link

JosChavz commented Jan 3, 2022

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

@psr-ai psr-ai linked a pull request Mar 19, 2024 that will close this issue
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants