Error calling decode on UploadedFile type?

Apologies for our docs typo! We have a PR out to fix that up so it should be resolved shortly.

Unfortunately we do not offer any shortcut to convert an UploadedFile to a string. It is a file-like object so you would first have to read the contents and then decode it in order to create a StringIO object.

stringio = StringIO(uploaded_file.getvalue().decode("utf-8"))

You could also wrap into a TextIOWrapper. TextIOWrapper can decode a buffer easily whereas StringIO takes in a string.

Ultimately it would depend on what type of object you would prefer to use in order to work with strings but both works!

1 Like