Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Azure-文件共享中具有给定扩展名的文件_Python_Azure_Azure Functions - Fatal编程技术网

Python Azure-文件共享中具有给定扩展名的文件

Python Azure-文件共享中具有给定扩展名的文件,python,azure,azure-functions,Python,Azure,Azure Functions,我正在使用连接到Azure文件共享并上载文件。我想选择扩展文件的扩展名,但我不能。我得到一个错误如下所示。如果我删除.txt一切正常。上传文件时有没有办法指定文件扩展名 错误: Exception: ResourceNotFoundError: The specified parent path does not exist. 代码: def main(blobin:func.InputStream): file\u client=ShareFileClient.from\u connecti

我正在使用连接到Azure文件共享并上载文件。我想选择扩展文件的扩展名,但我不能。我得到一个错误如下所示。如果我删除
.txt
一切正常。上传文件时有没有办法指定文件扩展名

错误:

Exception: ResourceNotFoundError: The specified parent path does not exist.
代码:

def main(blobin:func.InputStream):
file\u client=ShareFileClient.from\u connection\u string(conn\u str=“”,
share_name=“数据存储”,
file_path=“outing/file.txt”)
f=打开('/home/temp.txt',w+'))
f、 写入(blobin.read().decode('utf-8'))
f、 关闭()
#操作文件在这里
f=打开('/home/temp.txt',rb')
string_to_upload=f.read()
f、 关闭()
文件\客户端。上传\文件(字符串\上传到\上传)

我相信您出现此错误的原因是您的文件服务共享中不存在传出的文件夹。我获取了您的代码,并在有扩展和无扩展的情况下运行了它,在这两种情况下,我都得到了相同的错误

然后我创建了一个文件夹,并试图上传文件,我能够成功地做到这一点

以下是我使用的最终代码:

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..."

你是如何上传文件的?您可以检查共享中是否存在该文件吗?@GauravMantri我将字符串
string\u to\u upload
,进行一些操作并使用:
file\u client.upload\u file(string\u to\u upload)
上传。您可以编辑您的问题并包含完整的上传代码吗?另外,请检查文件是否正确上传。您可以使用Microsoft的存储资源管理器进行此操作。@GauravMantri文件已正确上载,如果我使用
file\u path=“outgoing/file”
。当我使用
file\u path=“outgoing/file.txt”
时,它会因上述错误而崩溃。事实上,当它使用
blobin
的名称时,它包含了它的目录。
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..."