0

I am trying to upload a folder using post request in python....

What i am trying to do?

@staticmethod
def upload_folder(root_url, file_name, username, password):
    url = root_url + '/upload'
    token = get_token(root_url, username, password)
    headers = {'content-type': 'multipart/form-data',
           'accept': 'application/json',
           'Authorization': 'something' + token}
    files = {
          'file': ('folder.zip;type', open('C:/path/folder.zip', 'rb')),
          'filename': 'package1'
    }
    data = json.dumps{'file_name': file_name}
    result = requests.post(url, headers=headers, files=files, data=data)
    return result.content.decode()

I have to enter the below details in the swagger,

file_name, folder in zip format...

I somehow think that the files parameter is passed wrong or is there some other way to pass folders....Could someone help me with this? thanks...

  • Possible duplicate https://stackoverflow.com/questions/22567306/python-requests-file-upload – soltysh Dec 21 '18 at 13:53
  • may be previous topic help your problem. [https://stackoverflow.com/questions/35939761/how-to-send-json-as-part-of-multipart-post-request#comment59538358_35939761](https://stackoverflow.com/questions/35939761/how-to-send-json-as-part-of-multipart-post-request#comment59538358_35939761) – xtrex Dec 21 '18 at 14:00

0 Answers0