hug
hug copied to clipboard
Simulating curl form upload
I have a upload script that goes like this
@hug.post('/upload', versions=1)
def upload(body):
content = list(body.values()).pop().decode('utf8')
It works fine if do
curl -F <filename>=@<path_to_file> api/v1/upload
But my unittest fails since it reads the file content into str and not utf-8 encoded.
with open(<path_to_file>, 'rb') as fs:
response = hug.test.post(hug_app, '/v1/upload', body={filename: fs})
So I get the following error. Is this a bug or?
content = list(body.values()).pop().decode('utf8')
AttributeError: 'str' object has no attribute 'decode'
Does curl do any encoding? This maybe a difference to the unit test call.