3

there is any sample showing how to use the blobstore api with ajax?

when i use forms works fine, but if i use jquery i don't know how to send the file and i get this error:

    blob_info = upload_files[0]
    IndexError: list index out of range

I have this code in javascript

function TestAjax()
{
 var nombre="Some random name";
 ajax={
    type: "POST",
    async:true,
    //dataType:"json",
    url:"{{upload_url}}",
    data:"nombreEstudio="+nombre,   
    error: function ()
    {
        alert("Some error");
        $("#buscando").html("");
    },            
    success: function()
             { alert("it's ok") }
 };             
 $.ajax(ajax);
}

When i use forms the file it's sended with a input tag (exactly like the doc's sample)

2 Answers 2

4

I wrote a series of posts about exactly this.

Sign up to request clarification or add additional context in comments.

Comments

2

Somehow you still need to get the multipart form data request to the server... so when you're using forms, I assume your <form> tag has something like this on it: enctype="multipart/form-data", right?

When you're just sending a "POST" via ajax, you're losing that multipart request, which is where your file is.

There are some jQuery "ajax file upload" plugins out there that may help you out.

Hope this helps!

** EDIT **

I guess one thing I can add to this is usually ajax file uploads (on the client) are implemented by either creating a hidden iframe, and using that iframe to submit a form, or using a form and posting it via JavaScript.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.