Convert File binary to text after download?

Hi all,

I’m using the boxsdk python lib to search for files, and then retrieve the file’s content as a string.

Something like:

search_results =<my_params>)
for file in search_results:
      content = file.content()

Problem is after this point, the Download API returns binary data that I can’t seem to decode, I’ve tried different encoding formats using python’s in-built decode, utf-8, ascii, iso, etc. Is there some way of properly decoding the binary data into string text?

Of course, I’m aware this won’t work for most file types, but would at least like to get .doc, .docx, .txt files as a starting point. I also don’t need to store the content into a file locally, just need to output the file contents.

Thank you!

Hi :wave:

Could you use a text representation instead of straight downloading the file? You can find more about those here.

Alex, Box Developer Advocate :avocado: