jeudi 26 septembre 2019

How to return an excel file in a flask API when my Ember client expects a JSON result? [on hold]

I am creating an excel file and attempting to use the flask send_from_directory functionality to allow the client to download the file that was just created.

    df1 = data
    file_name = 'test' + '.xlsx'

    writer = pd.ExcelWriter(
        file_name,
        engine='xlsxwriter'
    )

    df1.to_excel(writer, sheet_name='Sheet1')

    writer.save()

    return send_from_directory("", file_name, as_attachment=True)

The response on the client side is showing the file, but in a really messy way.

PK?FjÒ»a¯[Content_Types].xmlÍ

etc.

And I am getting an error on my client side ajax request that hits the API that creates the file:

Unexpected token P in JSON at position 0.

Before I am able to do anything with the file on the client side.

How do I send a file back to the client when the client is expecting a JSON value being returned by the API?




Aucun commentaire:

Enregistrer un commentaire