Hi

I want to upload a file via ajax. What I have working for when the file is 
stored in a folder, the problem and when I want it stored in a blob field.

*In upload_picture function I do not know how to put the value of 
image_blob *

The code is as follows

==================================================================================
/models/db.py
==================================================================================

tb_pictures = db.define_table('pictures',
        Field('name'),
        Field('image', 'upload', uploadfield='image_blob'),
        Field('image_blob', 'blob', writable=False, readable=False),
        )



==================================================================================
/controllers/default.py
==================================================================================
def pictures():
    return dict(f=LOAD('default', 'formpictures.load', ajax=True, ajax_trap=
True))

def formpictures():
    form = SQLFORM(tb_pictures, _id="formuploadajax")

    return dict(form=form)

def upload_picture():
    fd=request.vars.image
    tb_pictures.insert(
            name=request.vars.name,
            image=fd,
            *image_blob=fd,* #<===================
            )

    #return



==================================================================================
/views/default/formpictures.load
==================================================================================

<script>
    $(function(){
        $("#formuploadajax").on("submit", function(e){
            e.preventDefault();
            var f = $(this);
            var formData = new FormData(document.getElementById(
"formuploadajax"));
            $.ajax({
                url: "{{=URL('upload_picture')}}",
                type: "post",
                //dataType: "html",
                dataType: "script",
                data: formData,
                cache: false,
                contentType: false,
                processData: false,
                success: function (result) {
                    alert(result);
                }
            })
        });
    });
</script>

{{=form}}


José

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to