简体   繁体   English

通过 NextCloud api 的 Python 包装器将文件上传到 Nextcloud 时出错

[英]Error when uploading files to the Nextcloud via Python wrapper for NextCloud api

I use Python wrapper for NextCloud api in order to upload file from my local storage to Nextcloud:为 NextCloud api 使用 Python 包装器,以便将文件从本地存储上传到 Nextcloud:

file_name = "12.txt"
file_local_path = os.path.join(os.getcwd(), file_name)
a=nxc.upload_file("my_uid",file_local_path,"Test/")
print(a)

but I get an error:但我收到一个错误:

<OCSResponse: Status: Failed>

Then I add file name to Nextcloud path:然后我将文件名添加到 Nextcloud 路径:

file_name = "12.txt"
file_local_path = os.path.join(os.getcwd(), file_name)
a=nxc.upload_file("my_uid",file_local_path,"Test/12.txt")
print(a)

and I get success message:我收到成功消息:

<OCSResponse: Status: OK>

but uploaded file (12.txt) on Nextcloud is empty, while my file contains some text.但是在 Nextcloud 上上传的文件(12.txt)是空的,而我的文件包含一些文本。

Please tell me what I'm doing wrong.请告诉我我做错了什么。 And what is the right way to do it?什么是正确的方法?

Considering the samples provided for this API, you have to provide the file name, not just the parent directory:考虑到为此 API 提供的示例,您必须提供文件名,而不仅仅是父目录:

return self.nxc_local.upload_file(self.user_username, file_local_path, file_name)

Secondly, you say that you are trying to upload 12.txt but you code shows 12.jpg .其次,您说您正在尝试上传12.txt但您的代码显示12.jpg Perhaps you have mistyped?也许你打错了? If that is the case, you could be trying to open a 12.jpg that doesn't exist and therefore the file in the cloud is empty.如果是这种情况,您可能会尝试打开一个不存在的12.jpg ,因此云中的文件是空的。 In any case, take a look at the API reference as well as the provided samples to solve your problem.无论如何,请查看API 参考以及提供的示例来解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用启用了 2 因素身份验证的 python 脚本从 nextcloud 下载文件 - Downloading files from nextcloud with python script with 2-factor authentication enabled 使用 python 连接到 SNAP(nextcloud) 中的 MySQL - Connecting to MySQL in SNAP(nextcloud) with python 使用 gitlab runner 通过 webdav 访问 Nextcloud 的问题 - Problems accessing Nextcloud via webdav with gitlab runner 上传图片时出现Dropbox API错误(Python) - Dropbox API error when uploading image (Python) 使用Dropbox API和Python将大文件上传到Dropbox会导致错误 - Uploading Large Files to Dropbox using Dropbox API and Python Results in Error 通过python上传到SQL表时,CSV数据导致错误 - CSV data causes error when uploading to SQL table via Python 通过Python API包装器在SendGrid API v3中使用替代项时出现错误请求 - Bad Request when using Substitutions with the SendGrid API v3 via the Python API Wrapper 如何使用 easywebdav 使用 python 将 object 之类的文件上传到 nextcloud - How can I Upload file like object to nextcloud with python using easywebdav 通过 Flask 上传 2 个单独的文件,用于 Python 处理 - Uploading 2 individual files via Flask for Python Processing Python脚本通过FTP上传文件 - Python Script Uploading files via FTP
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM