我正在使用this连接到Azure文件共享并上载文件。我想选择扩展名文件的扩展名,但我不能。我得到了一个错误显示如下。如果我删除.txt,一切都会正常工作。有没有办法在上传时指定文件扩展名?
错误:
Exception: ResourceNotFoundError: The specified parent path does not exist.代码:
def main(blobin: func.InputStream):
file_client = ShareFileClient.from_connection_string(conn_str="<con_string>",
share_name="data-storage",
file_path="outgoing/file.txt")
f = open('/home/temp.txt', 'w+')
f.write(blobin.read().decode('utf-8'))
f.close()
# Operation on file here
f = open('/home/temp.txt', 'rb')
string_to_upload = f.read()
f.close()
file_client.upload_file(string_to_upload)发布于 2020-01-28 21:11:20
我认为您收到此错误的原因是因为您的文件服务共享中不存在outgoing文件夹。我拿了你的代码,并运行它,无论有没有扩展,在这两种情况下,我得到了相同的错误。
然后我创建了一个文件夹,并尝试上传文件,我成功地做到了。
下面是我使用的最终代码:
from azure.storage.fileshare import ShareFileClient, ShareDirectoryClient
conn_string = "DefaultEndpointsProtocol=https;AccountName=myaccountname;AccountKey=myaccountkey;EndpointSuffix=core.windows.net"
share_directory_client = ShareDirectoryClient.from_connection_string(conn_str=conn_string,
share_name="data-storage",
directory_path="outgoing")
file_client = ShareFileClient.from_connection_string(conn_str=conn_string,
share_name="data-storage",
file_path="outgoing/file.txt")
# Create folder first.
# This operation will fail if the directory already exists.
print "creating directory..."
share_directory_client.create_directory()
print "directory created successfully..."
# Operation on file here
f = open('D:\\temp\\test.txt', 'rb')
string_to_upload = f.read()
f.close()
#Upload file
print "uploading file..."
file_client.upload_file(string_to_upload)
print "file uploaded successfully..."https://stackoverflow.com/questions/59932638
复制相似问题