O365 / python-o365

A simple python library to interact with Microsoft Graph and Office 365 API
Apache License 2.0
1.68k stars 424 forks source link

Download drive file as stream & skip copy to a path #449

Open mohanrkrishna opened 4 years ago

mohanrkrishna commented 4 years ago

Hi - Thanks for nice tool. I am able to get document names from Teams/channel folders using sharepoint & drive functions. Need to download 100+ excels there , parse and load to database.

if files:
    numberDoc = files[0]
    print("... copying to local machine")
    operation = numberDoc.download(to_path=dl_path)
else:
    print("File not found!")
    exit()

print("Reading sheet to dataframe")
df = pd.read_excel(f'{dl_path}/{f_name}')

In above example provided , it expected to_path. Our app will be deployed to Azure web apps , so cannot download to a path

Looking for thoughts how to get content stream from current library method & store to dataframe. I see download , but it expects to_path.

Please let me know if it is doable. Thanks!

alejcas commented 4 years ago

For the moment downloading a file requires an actual file on disk, but the code can be easely changed so it can write to a BytesIO object, so all will be kept on memory.

A stream of bytes is also possible.

mohanrkrishna commented 4 years ago

Thanks @janscas Love the tool.