[英]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.