title: Upload file from Javascript to Google Cloud Endpoint
body: <p>I'm creating a web app using only <strong>HTML5</strong> + <strong>Javascript</strong> + <strong>jQueryMobile</strong> and I wanted to upload a file to a <strong>Google App Engine</strong> web application using a <strong>Google Cloud Endpoint</strong>, also created by me.</p>
  
  <p>As I control both sides, I can (and want to) create the simplest interaction possible.</p>
  
  <p>As for the Endpoint, I thought of creating a method like this:</p>
  
  <pre><code>@ApiMethod(
    name = "uploadFile",
    path = "upload_file",
    httpMethod = HttpMethod.POST
  )
  public void uploadFile(File file) {
    //process the file
  }
  </code></pre>
  
  <p>This <code>File</code> class could contain a field <code>fileData</code> of type Blob, or byte[] or something like that, repersenting the file data... Something like:</p>
  
  <pre><code>public class File {    
    private String fileName;
    private long fileSize;
    private Blob fileData;    
    //getters and setters
  }
  </code></pre>
  
  <p>So the first question would be: <strong>what's the most suitable type for this field</strong> <code>fileData</code><strong>?</strong></p>
  
  <p>And, taking into account the type selected for the field, <strong>how could I create the necessary POST request for that endpoint method form Javascript/jQuery?</strong></p>
  
  <p>Basically I need to create a POST request to <code>http://myappid.appspot.com/_ah/api/files/v1/upload_file</code> adding the <code>File</code> object in the POST data.</p>
  
  <p><em>Note: I'm sorry I haven't tried anything for the Javascript code because I'm not familiar at all with this technologies, so I'd appreciate any help...</em></p>