0

I'm trying to upload a file into Azure blob storage. My application is hosted in the Azure app service Linux server. Now when I request to file upload from a remote machine, I want a file to be uploaded from the given path.

I have three request parameters which take the value-form GET request

  1. https://testApp.azurewebsites.net/blobs/fileUpload/
  2. containerName:test
  3. fileName:testFile.txt
  4. filePath: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') the value which I get from the request is C:\Users\testUser\Documents\ becasue of which I get this error

OSError: [Errno 22] Invalid argument: 'C:\Users\testUser\Documents\testFile.txt'

all I want is to get the same path that I send in the request. Since the application is hosted in the Linux machine it treats the path as a UNIX file system if I use OS.path

please help me with this

Ivan Yang
  • 28,783
  • 2
  • 29
  • 49
  • Do you have more issues about this? – Ivan Yang Oct 04 '19 at 05:13
  • Thanks @Ivan, I get it, the file should be locally present to use create_blob_from_path. But what should be the approach if there is a client-server scenario say I want to request a file upload from the client-side? – Gowtham Babu Oct 07 '19 at 13:34
  • Since you're using web app, here is an [issue](https://stackoverflow.com/questions/54729137/django-azure-upload-file-to-blob-storage) which use django framework to upload local file to blob storage. – Ivan Yang Oct 08 '19 at 01:38

1 Answers1

1

As per the error message says, the local path is invalid for 'C:\Users\testUser\Documents\testFile.txt'. It means that there is no such file path in your local system.

If you want to use create_blob_from_path method, you should download the file to your local system first, then use the method to upload to blob storage.

Or you can get the stream / text of the file from remote, then use create_blob_from_stream / create_blob_from_text method respectively.

Ivan Yang
  • 28,783
  • 2
  • 29
  • 49