0

I'm trying to send an array of images using fetch to a flask endpoint, but I can't seem to get the data across.

Fetch:

async () => {
  const data = new FormData();
  data.append('images', imagesArray);

  const response = await fetch('/upload', {
    method: 'POST',
    body: data
  });
}

Endpoint:

@main.route('/upload', methods=['POST'])
def process_image():
  if request.files:
    images = request.files.getlist('images[]')
    print(images)

Nothing gets printed to the server. However, if I just send a single image and set images = request.files['images'], then the image object will be printed out.

What am I doing wrong? Any help would be much appreciated!

Kilter
  • 41
  • 5
  • Does this answer your question? [How do I upload a file with the JS fetch API?](https://stackoverflow.com/questions/36067767/how-do-i-upload-a-file-with-the-js-fetch-api) – Carlos Jan 03 '20 at 21:14
  • So I think I understand how to send a single image, but I'm having trouble with sending an array of images. – Kilter Jan 03 '20 at 21:30

0 Answers0