I have a simple csv file that I want to upload to my app using an HTTP endpoint
local code for uploading
import requests
files = {'upload_file': open("testfile33.csv",'rb')}
url='https://ak-api.anvil.app/_/api/upload'
response = requests.post(url, files=files)
I am unable to get the anvil server code (below) for http endpoint working properly to extract the file from the request. Here is what I have so far.
Greatly appreciate any help…
import anvil.server
@anvil.server.http_endpoint("/upload", methods="POST")
def upload():
bb = anvil.server.request.body.get_bytes()
print(bb)
print result
b'--f0dbf62bee43b81ba5c7a76fb58af925\r\nContent-Disposition: form-data; name="upload_file"; filename="testfile33.csv"\r\n\r\nID,NAME\n1, "Jun"\n2, "Zune"\n3, "Boone"\r\n--f0dbf62bee43b81ba5c7a76fb58af925--\r\n'
Additional questions…
- I see the data in the message body, but how to grab it?
- Is this the method for large files say a 50 MB file?