Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

uploading multiple files with pyramid

Trying to upload multiple files at once using python. The upload.html source code is as followed:

        <form name="frmRegister" method="post" accept-charset="utf-8" enctype="multipart/form-data" class="form-horizontal">
             <div class="control-group">
                 <div class="controls">
                    <input type="file" name="files" multiple='multiple'>
                 </div>
             </div>
             <div class="control-group">
                 <div class="controls">
                    <input class="btn btn-primary" type="submit" name="btnSubmit" value="Add Product" />
                 </div>
             </div>
        </form>

in my admin.py:

    @view_config(context="mycart:resources.Product", name="add", renderer='admin/mall/product/add.jinja2', permission = 'admin')
    @view_config(context="mycart:resources.Product", name="add", request_method="POST",  renderer='admin/mall/product/add.jinja2', permission = 'admin')
    def product_add(context, request):
        if 'btnSubmit' in request.POST:
            print ("files >>> ", request.POST['files'])

in my terminal, it is showing just FieldStorage('files', u'DSC01973.JPG') whereas I've selected 'DSC01975.JPG', 'DSC01976.JPG'.

Why is this so?

like image 681
Gino Avatar asked Dec 27 '12 07:12

Gino


People also ask

What is a multipart file upload?

Multipart upload allows you to upload a single object as a set of parts. Each part is a contiguous portion of the object's data. You can upload these object parts independently and in any order. If transmission of any part fails, you can retransmit that part without affecting other parts.


1 Answers

I've found a way to solve it, I believe there are many others, if there are, please feel free to holler out:

    fileslist = request.POST.getall('files')
    print ("My files listing: ", fileslist)
    for f in fileslist:
        print ( "individual files: ", f )
like image 58
Gino Avatar answered Oct 25 '22 09:10

Gino