Skip to main content

Convert File binary to text after download?

  • September 11, 2023
  • 1 reply
  • 206 views

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 = box.search().query(<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!

1 reply

smartoneinok Box
Forum|alt.badge.img
  • Senior Developer Advocate
  • 181 replies
  • September 15, 2023

Hi 👋


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


Thanks,

Alex, Box Developer Advocate 🥑


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings