hug icon indicating copy to clipboard operation
hug copied to clipboard

Simulating curl form upload

Open NixBiks opened this issue 6 years ago • 1 comments

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'

NixBiks avatar Apr 20 '19 19:04 NixBiks

Does curl do any encoding? This maybe a difference to the unit test call.

bernhardreiter avatar Jun 16 '20 20:06 bernhardreiter