0

i work on a little flask app, which consists in searching docs with keywords (ElasticSSearch) and upload docs in cluster.

Searching docs works fine but upload is hard, i can do it with curl but i have some problems

My curl command is like:

curl -F "file=@pdf-test.pdf" "http://127.0.0.1:pdf-8080/fscrawler/_upload"

My html is:

<form id="uploadbanner" enctype="multipart/form-data" method="post" action="/">
   <input id="fileupload" name="myfile" type="file" />
   <input type="submit" value="submit" id="submit" />
</form>

in order to create upload button for the client.

I saw many topic about requests library, but my py code does not work, i really do not understand what i do wrong, and i am pretty lost.

I give you what i tried:

def upload():
url="http://127.0.0.1:8080/fscrawler/_upload"
    if request.method == 'POST':
        payload = open("test.pdf")

        r = requests.post(url, data=payload)

Thanks for help, and have a good day :)

VanCleef
  • 1
  • 1

1 Answers1

0

Try:

curl -F "myfile=@pdf-test.pdf" "http://127.0.0.1:pdf-8080/fscrawler/_upload"

The name of your file input needs to be the same in curl and html.

Joost
  • 3,609
  • 2
  • 12
  • 29
  • Yes i forget it ! But it does not change anything, i think the problem is in html. There is some things i do not understand well: For example, when i choose a file with upload button, where is my file ? For searching, i had no problems because there is no "object" to manipulate, i just put the content of search in variable then i query my es cluster. But now there is a file and I do not even understand what i do sometimes.. – VanCleef Jun 08 '18 at 15:35