Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8885849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:24:44+00:00 2026-06-14T21:24:44+00:00

I have a javascript frontend connect to a Google App Engine backend. The instructions

  • 0

I have a javascript frontend connect to a Google App Engine backend. The instructions for uploading a file to Blobstore assume you are using JSPs, which I am not. The example for creating a file drop handler assume you just want to send the file up by itself in a post.

This works for sending the file up:

var files = event.getBrowserEvent().dataTransfer.files;
if (files.length > 0) {
  if (files.length > 1) {
    console.log('Too many files!');
  } else {
    var file = files[0];

    var xhr = new goog.net.XmlHttp();
    xhr.open('POST', '/imageUpload?gwt.codesvr=localhost:9997');
    xhr.send(file);
  }
}

But this is just sending the data directly to my servlet. I could add a form to my html but as far as I can tell closure doesn’t like setting inputs of type file.

Suggestions as to how I can upload my files to the Blobstore?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T21:24:45+00:00Added an answer on June 14, 2026 at 9:24 pm

    With some help from this answer, I finally figured this out.

    First off, make sure sessions are enabled in your appengine-web.xml: <sessions-enabled>true</sessions-enabled>

    I ended up writing two separate servlets, one that creates the upload URL and the second that handles the redirect after the image is written to the blobstore.

    Image upload URL servlet

    public void doGet(HttpServletRequest pRequest, HttpServletResponse pResponse) throws IOException {
        BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
        Map<String, String> payload = new HashMap<String, String>();
    
        payload.put("url", blobstoreService.createUploadUrl("/imageUpload"));
    
        LOGGER.info("Payload: " + GSON.toJson(payload));
    
        pResponse.setContentType("application/json");
        pResponse.getWriter().println(GSON.toJson(payload));
    }
    

    Client side image upload requestor

    // request function
    ...
    goog.net.XhrIo.send('/imageUploadURL', goog.bind(this.handleURLReceived, this));
    ...
    
    // response handler function
    myapp.ImageDrop.prototype.handleURLReceived = function(event)
    {
      this.postURL = this.extractValidJson(event).url;
      myapp.logger.fine('Response: ' + this.postURL);
    };
    

    extractValidJson(event) is just a utility function I wrote to pull out the json response.

    Once we have a valid URL, we can allow uploads.

    Client side upload drop sender

    // In constructor
    ...
    var dropZone = goog.dom.getElement('image-drop');
    var handler = new goog.events.FileDropHandler(dropZone, true);
    goog.events.listen(handler, goog.events.FileDropHandler.EventType.DROP, goog.bind(this.handleDrop, this));
    ...
    
    // FileDropHandler
    myapp.ImageDrop.prototype.handleDrop = function(event)
    {
      var files = event.getBrowserEvent().dataTransfer.files;
    
      var file = files[0]; // IRL, do error checking
    
      this.xhr = new goog.net.XmlHttp();
      this.xhr.open('POST', this.postURL, true); // asych
      this.xhr.onreadystatechange = goog.bind(this.uploadResponseHandler, this);
    
      var form_data = new FormData();
      form_data.append('file', file); // name is arbitrary, must match in servlet      
      this.xhr.send(form_data);
    };
    

    Image upload redirect servlet

    public void doPost(HttpServletRequest pRequest, HttpServletResponse pResponse) throws IOException {
        Map<String, List<BlobKey>> blobs = blobstoreService.getUploads(pRequest);
    
        // 'file' matches param name from form
        for (BlobKey key : blobs.get("file")) {
            LOGGER.info("We have a KEY!!!! " + key);
            blobstoreService.delete(key); // Just testing
        }
    
        // Make this a real response        
        pResponse.setContentType("text/html");
        pResponse.getWriter().println("OK");
    

    }

    Then you can do whatever in your uploadResponseHandler. Request finished is 4 (see this).

    myapp.ImageDrop.prototype.uploadResponseHandler = function(event)
    { 
      if (this.xhr.readyState === myapp.ImageDrop.REQUEST_FINISHED) {
        myapp.logger.fine('Request finished!');
      }
    };
    

    Not so bad once all the pieces come together.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a system in which frontend is in javascript/ajax and the backend is
I have Javascript function defined in the main index.html file. One part of this
I have javascript code embedded inside a html template file. When I load this
I have JavaScript code which copies the value of input file and paste it
I am creating a website using JavaScript/ASP.NET/C#/CSS/HTML/Compact SQL server. I have the majority of
I Have following in my struts.xml file <action name=ProductVerification class=com.frontend.ProductVerification> <result name=success>/jsp/product_verification.jsp</result> <result name=input>/jsp/product_verification.jsp</result>
I have a website with a frontend and a backend that all run through
How can I edit a javascript file using php. I want to change the
I have been working with Django as backend and using jQuery for the front
I have a problem where my javascript is not working in a separate file,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.