如何使用Azure函数应用将文件从桌面上传到Azure Blob存储
我正在尝试通过Azure函数应用上传一些文件。首先,我阅读了一些Excel文件,然后使用PANDA进行一些清洁过程,并想将其上传到Azure功能应用程序。离线每个作品都很好,但是当我发布到Azure时,它给出了错误500 。 我猜它无法从我的PC获取文件。
我的代码看起来像这样:
#I get my files offline
AISauftragID = req.params.get('ID','756382')
Position = req.params.get('Position','7')
location = fr'C:\Users\bb\ff\Doc\VS Code\{ID}-{Position}'
#Some Cleaning using pandas
#connecting to Azure
blob_service_client = BlobServiceClient.from_connection_string("blablabla")
# Instantiate a new ContainerClient
container_client = blob_service_client.get_container_client('foldername')
try:
# Create new Container in the service
container_client.create_container()
properties = container_client.get_container_properties()
except ResourceExistsError:
print("Container already exists.")
blob = BlobClient.from_connection_string(conn_str="blablabla",
container_name="foldername",
blob_name="filename")
if blob.exists():
logging.info('filename.csv exists')
return func.HttpResponse(
"filename.csv exists",
status_code=200)
else:
blob_client = container_client.get_blob_client("filename.csv")
# upload data
blob_client.upload_blob(dataframe.to_csv(index=False, encoding = "utf-8"), blob_type="BlockBlob")
return func.HttpResponse(
"Konto.csv exists",
status_code=200)
我的function.json文件看起来像这样:
{
"scriptFile": "__init__.py",
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get",
"post"
]
},
{
"type": "http",
"direction": "out",
"name": "$return"
}
]
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
那是正确的。 Azure函数在Azure云数据中心的某个地方运行。该功能无法访问本地工作站的本地硬盘。另外,您真的不想这样做,因为这将是主要的安全风险。
如前所述,您似乎有使用Azure函数上传本地文件的想法。您需要一些客户端进程(例如浏览器或应用程序)将文件发送到Azure,然后可以编写Azure函数或其他处理该文件。
要处理一个文件,您要么创建一个http触发的azure函数,该函数接受文件内容或您将文件上传例如,azure blob存储并创建触发斑点 / 事件网格触发 azure函数来处理文件。
That is correct. The azure function runs somewhere in an Azure Cloud data center. There is no way this function can access the local harddrive of an on-premises workstation. Also, you really don't want to because it would be a major security risk.
You seem to have the idea to use an azure function for uploading the local file, as stated, that is a no go. You need some client process like a browser or application to send the file to azure and then you can write an azure function or whatever to process that file.
To process a file you either create an http triggered azure function that accepts a POST action with the file content or you upload the file to, for example, azure blob storage and create a blob triggered / event grid triggered azure function to process the file.