python requests file upload

后端 未结 4 680
醉梦人生
醉梦人生 2020-11-22 13:20

I\'m performing a simple task of uploading a file using Python requests library. I searched Stack Overflow and no one seemed to have the same problem, namely, that the file

4条回答
  •  再見小時候
    2020-11-22 13:52

    In Ubuntu you can apply this way,

    to save file at some location (temporary) and then open and send it to API

          path = default_storage.save('static/tmp/' + f1.name, ContentFile(f1.read()))
          path12 = os.path.join(os.getcwd(), "static/tmp/" + f1.name)
          data={} #can be anything u want to pass along with File
          file1 = open(path12, 'rb')
          header = {"Content-Disposition": "attachment; filename=" + f1.name, "Authorization": "JWT " + token}
           res= requests.post(url,data,header)
    

提交回复
热议问题