【发布时间】:2020-01-31 03:07:18
【问题描述】:
我正在尝试将文件上传到 Azure Blob 存储。我的应用程序托管在 Azure 应用服务 Linux 服务器中。 现在,当我请求从远程机器上传文件时,我希望从给定路径上传文件。
我有三个请求参数,它们采用值形式的 GET 请求
- https://testApp.azurewebsites.net/blobs/fileUpload/
- 容器名称:测试
- 文件名:testFile.txt
-
文件路径:C:\Users\testUser\Documents
@app.route("/blobs/fileUpload/") def fileUpload(): container_name = request.form.get("containerName") print(container_name) local_file_name =request.form.get("fileName") print(local_file_name) local_path =request.form.get('filePath') ntpath.normpath(local_path) print(local_path) full_path_to_file=ntpath.join(local_path,local_file_name) print(full_path_to_file) # Upload the created file, use local_file_name for the blob name block_blob_service.create_blob_from_path(container_name, local_file_name, full_path_to_file) return jsonify({'status': 'fileUploaded'})
local_path =request.form.get('filePath') 我从请求中得到的值是 C:\Users\testUser\Documents\ 因为我得到了这个错误
OSError: [Errno 22] 无效参数:'C:\Users\testUser\Documents\testFile.txt'
我想要的只是获得与我在请求中发送的相同路径。由于应用程序托管在 Linux 机器中,如果我使用 OS.path,它会将路径视为 UNIX 文件系统
请帮帮我
【问题讨论】:
-
您还有其他问题吗?
-
谢谢@Ivan,我明白了,该文件应该在本地存在以使用 create_blob_from_path。但是如果有一个客户端-服务器场景说我想从客户端请求文件上传,应该怎么做呢?
-
由于您使用的是网络应用程序,这里有一个issue,它使用 django 框架将本地文件上传到 blob 存储。
标签: python azure rest file azure-blob-storage