How to Read an Existing Excel File Directly from M-Files via API?


I’m working on integrating M-Files with an external Python application. I want to read the contents of an existing Excel file stored in M-Files directly through the API, ideally without having to download the file to local storage first.

Is it possible to access and read the Excel file’s data directly via the M-Files REST or COM API? If so, could you please share some guidance or sample code?

Thanks in advance for your help!

Parents Reply
  • Hi  ,

    Thank you for your prompt response and for sharing the useful resources and links.

    I understand that typically the file is accessed via a stream download. However, I'm trying to explore if there’s any supported way to read an Excel file's contents directly from M-Files via the REST or COM API without downloading it to disk, even if only into memory (e.g., using a stream/byte array that I can pass to a Python in-memory parser like pandas.read_excel(BytesIO(...))).

    Would you happen to have any guidance or suggestions for achieving this, or could you confirm if downloading the file stream is the only viable approach?

    I’d greatly appreciate any direction or sample pointers, especially for accessing the file content via REST in a way that's compatible with in-memory processing in Python.

    Thanks again for your help!

    Best regards,
    Nandini R

Children
  • I don't think I follow. Accessing the data as above is exactly what I think you need; read the response stream in memory and do not save it to disk. This is done via the "contents" endpoint. 

    If this isn't what you want then perhaps someone else can assist, as I obviously don't understand the nuance of your query. 

  • Thank you for your input! Accessing the file content directly via the "contents" endpoint and reading it into memory worked perfectly for my use case — no need to save the file locally.

    Here’s a simplified example of how I read the Excel file from the response stream into a pandas DataFrame:

    import requests
    import pandas as pd
    from io import BytesIO

    # Assume 'download_url' and 'headers' are already set up correctly
    response = requests.get(download_url, headers=headers, stream=True)
    response.raise_for_status()

    excel_data = BytesIO(response.content)
    df = pd.read_excel(excel_data)

    print(df.head()) # Confirm data is loaded

    Thanks again for clarifying — this approach is exactly what I needed!