Code Monkey home page Code Monkey logo

Comments (7)

chfw avatar chfw commented on June 6, 2024

https://github.com/pyexcel/pyexcel-webio/blob/master/pyexcel_webio/__init__.py#L197 returns:

{'file_content': b'', 'name_columns_by_row': 0, 'file_type': 'xlsx'}

Hence, it means request.files['file'].read() == "", empty file was uploaded.

Here's how I upload a file programmatically https://github.com/pyexcel/Flask-Excel/blob/master/tests/test_upload_n_download_excel.py#L36

Here's how I upload file using html form https://github.com/pyexcel/Flask-Excel/blob/master/examples/tiny_example.py#L19

from flask-excel.

chfw avatar chfw commented on June 6, 2024

And what you can test is:

@pre_save(sender=BulkMessage)
def on_bulk_message_save_handler(model_class, instance, created):
    import pdb;pdb.set_trace()
    print(request.files['file'].read())
    instance.file_fields = request.get_array(field_name='file')

from flask-excel.

tiktuk avatar tiktuk commented on June 6, 2024

Yeah, the strange thing is that the file is in fact uploaded every time.

And it looks correct here in the request:

>>> request.files
ImmutableMultiDict([('file', <FileStorage: 'SMS_dummy_data.xlsx' ('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')>)])

But it's true that I can't read() it:

>>> print(request.files['file'].read())                                              
b''

But why is it correctly uploaded then? I'm sure this is some basic Flask noob mistake. Probably not anything wrong with your library.

from flask-excel.

tiktuk avatar tiktuk commented on June 6, 2024

Oh yeah, the tiny example works perfectly.

from flask-excel.

chfw avatar chfw commented on June 6, 2024

Just in case we may have skipped this line:

<form .. enctype=multipart/form-data>

according to Flask documentation

from flask-excel.

tiktuk avatar tiktuk commented on June 6, 2024

That line is generated by the FileUploadField from Flask-Admin. And I do in fact see the file contents in the request in Firefox' inspector. And it does get uploaded. Really weird,

from flask-excel.

chfw avatar chfw commented on June 6, 2024

It was found in pyexcel/pyexcel#67 that the upload file stream could have been consumed. Maybe a file.seek(0) could help.

from flask-excel.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.