1

I want to upload image files using blobstore API using AJAX POST and not as html form submission. Based on Google search, i figured out that this could be done by uploading the image file to Google Cloud Storage using blobstore API. I went through this link but I am not able to understand it.

I have an html input element of type "file":

Pic <input type="file" name="pic" id="pic_file"> 
Name <input type="text" name="name" id="name"> 
Email <input type="text" name="email" id="email"> 

I have an AJAX call to send other input field values to my python backend:

var user_data = "&name="+$("#name").val() + "&email="+$("#email").val();  
$.post("/admin", user_data, after_edit); 

In my python file,

class Admin(BaseRequestHandler): 
    def get(self): 
        :: 
        template_values = { 'url': url, } 
        self.generate('adminpage_1.html', template_values); 
    def post(self): 
        name = self.request.get('name') 
        email = self.request.get('email') 

app = webapp2.WSGIApplication([ 
    ('/', MainHandler), 
    ('/admin', Admin), 
], debug=True) 

I want to avoid using additional plugins for this if there is a way out without them

gsinha
  • 1,165
  • 2
  • 18
  • 43
  • possible duplicate of [Blobstore upload + Ajax/Alternative](http://stackoverflow.com/questions/7194559/blobstore-upload-ajax-alternative) – Jimmy Kane Jan 26 '14 at 15:21
  • Thanks Jimmy for the reference but as mentioned I would prefer not to use any plugin. The referred answer uses Plupload plugin – gsinha Jan 26 '14 at 15:31
  • Here is an example http://upload.gae-init.appspot.com/resource/upload/ – Lipis Jan 26 '14 at 15:38
  • NOTE: Blobstore and Google Cloud Storage (GCS) are two different technologies for holding your blobs. If you're just starting out and trying to learn app engine, then forget about GCS and just use Blobstore directly ( https://developers.google.com/appengine/docs/python/blobstore/#Python_Uploading_a_blob ) – Nicholas Franceschina Jan 27 '14 at 22:14
  • Thanks Lipis for the link; I could not find much documentation on how to use that since their docs links are not yet ready.. – gsinha Jan 28 '14 at 16:34
  • Thanks Nick.. I get your point.. I am building an app for which I need to upload an image along with some other data without refreshing the page.. I want to avoid using form submit.. I am trying to explore some solution using the plugin http://malsup.com/jquery/form/ – gsinha Jan 28 '14 at 16:38

0 Answers0