title: Calculating length of mp4 video after upload to Google Cloud Storage from GAE
body: <h2><strong>Context</strong></h2>
  
  <p>My application enables users to upload an .mp4 file to Google Cloud Storage through Google App Engine using the createUploadUrl() pattern.  The upload works fine and I'm able to obtain the corresponding FileInfo object in the handler.  I'm using the App Engine SDK 1.8.2 for Java.  </p>
  
  <h2><strong>The Challenge</strong></h2>
  
  <p>I need to grab the "duration" property off of the .mp4 file and store it in my database but the FileInfo object doesn't provide access to this metadata.  I have a few ideas on how I might go about doing this (which I've listed below) but none of them are very straightforward given that the project I'm working on has several legacy dependencies.  </p>
  
  <p>I'd love to hear any ideas or suggestions you have on how to tackle this (and ideally any success stories if you have!) </p>
  
  <h2><strong>Ideas</strong></h2>
  
  <ol>
  <li>I know that there are scripts and utilities like ffmpeg and mdls (for mac) that can read metadata off of the file but my understanding is that these wouldn't be able to run in Google App Engine and I would need to kick off separate processes using something like Google Compute Engine.  </li>
  <li>I could create a custom flash upload control that reads the duration logic when the user selects the file for upload and passes it in through standard form submission.</li>
  <li>I'm also aware that there's a Google Cloud Storage JSON API that's been in Beta stage now.  I don't see any functionality that would allow me to read the "duration" property off of the .mp4 file but I may be missing something...</li>
  </ol>
  
  <h2><strong>Code</strong></h2>
  
  <p>HTML Form</p>
  
  <pre><code>&lt;form name="myForm" id="myForm" action="&lt;%=createUploadUrl("/upload, uploadOptions)%&gt;" method="POST" enctype="multipart/form-data"&gt;
      &lt;input type="file" name="uploadFileControl" id="uploadFileControl" value="Select..."&gt;
      &lt;input type="submit" value="Submit"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Server Side Handler</p>
  
  <pre><code>DAO dao = new DAO();
  BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
  Map&lt;String, List&lt;FileInfo&gt;&gt; fileInfos = blobstoreService.getFileInfos(req);
  List&lt;FileInfo&gt; uploadedFile = fileInfos.get("uploadFileControl");
  
  if(uploadedFile != null) {
      FileInfo file = uploadedFile.get(0);
      String fileName = file.getFilename();
  }
  </code></pre>