Uploading file to API and displaying JSON return

Hey, I’m new to Bubble but here is what I am trying to do:

File Uploader > POST API (own Flask app hosted on pythonanywhere for current dev/debug) > returns area of features in file > display this in a text box

My API seems to work: The call is setup as:

  • Name: Upload user file.
  • Use as: Action.
  • Data Type: File.
  • Method: POST.
  • URL: theUrlForMyAPI
  • Body: Form-data.
  • Add Parameters:
  • Key: file.
  • Value: a file from my laptop and ticked the ‘upload file’. I also tried to have it as " <> " but does not seem to change anything:

I can see the right name of the file being returned and the area of the feature in the API plugin.
Now, My workflow is like this and I believe that the problem is that I can’t select anything else than the URL response from my API…:

I have tried to return different values from the API but none seem to work (but the flow works as I can see different file names and area of feature being returned when I upload different files on my bubble app). These are the 2 ways I’ve tried to return things from my API:
1)
return render_template(‘index.html’, file_name=file.filename, area=area)
2)
jsonify({“filename”: file.filename, “area”: area})

I’ve checked and I can get both to return these values on Postman but I can’t display the returned values on my bubble app. I thought I would be able to find the ‘area’ variable from my json return but can’t see it in the workflow…

Do I need to change something on my bubble app or on my Flask app to make it work?

The issue is that you have set file as data type on top right on API connector but you should set json. Reinitialize API call.

1 Like

I swear I tried this earlier and it didn’t like it… Anyway, now it seems to work, thanks!

Thanks a lot Jici for the quick answer!

1 Like