繁体   English   中英

无法在 azure blob 中上传文件

[英]unable to upload file in azure blob

我正在尝试将文件上传到 Azure blob 存储中。 我的应用程序托管在 Azure 应用服务 Linux 服务器中。 现在,当我请求从远程机器上传文件时,我希望从给定路径上传文件。

我有三个请求参数,它们采用值形式的 GET 请求

  1. https://testApp.azurewebsites.net/blobs/fileUpload/
  2. 容器名称:测试
  3. 文件名:testFile.txt
  4. 文件路径: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 文件系统

请在这件事上给予我帮助

根据错误消息,“C:\Users\testUser\Documents\testFile.txt”的本地路径无效。 这意味着您的本地系统中没有这样的文件路径。

如果要使用create_blob_from_path方法,应先将文件下载到本地系统,然后使用该方法上传到 blob 存储。

或者您可以从远程获取文件的 stream / text ,然后分别使用create_blob_from_stream / create_blob_from_text方法。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM