title: Salesforce - Is it possible to display image file from ContentVersion to custom visualforce page?
body: <p>I wrote one simple Visualforce page that let user upload an image file then
  save the file to <code>ContentVersion</code> object.</p>
  
  <p>Now <strong>I want to display the saved image in my custom visualforce page.</strong> Is it even possible?
  Looks like <code>&lt;apex:image&gt;</code> cannot be used. Also <code>&lt;img href="{!cv.contentVersion}"...&gt;</code> had no luck.</p>
  
  <p>The real problem is I did upload the image file successfully but what is the URL to it?
  I tested with random URL outside on google and I can display the image (like /../..some.jpg"). But I can't figure out what is the absolute URL for the image file that has been uploaded to contentversion.</p>
  
  <p>NOTE: This is not static resource as my users may upload image to change their user image often.</p>
  
  <p><strong>Code</strong></p>
  
  <pre><code>public with sharing class ImageUploadTestController {
  
      public blob file { get; set; }
      public String imageFilePath { get; set; }
  
      public ContentVersion cv { get; set; }
  
      public ImageUploadTestController() {
          cv = [select id, versionData, title, pathOnClient FROM ContentVersion limit 1];
      }
  
      //fill out the inputFile field and press go. This will upload file to the server
      public PageReference go() {
          ContentVersion v = new ContentVersion();
          v.versionData = file;
          v.title = 'some title';
          v.pathOnClient ='/foo.jpeg';
          insert v;
  
          return new PageReference('/' + v.id);
      }
  
      //v.id sample
      //069A00000009Ux3
  
  }//end class
  </code></pre>
  
  <p><strong>Visualforce page</strong></p>
  
  <pre><code>&lt;apex:page controller="ImageUploadTestController"&gt;
      &lt;apex:form &gt;
      &lt;apex:inputFile value="{!file}" /&gt;
  
      &lt;apex:commandbutton action="{!go}" value="go"/&gt;
      &lt;/apex:form&gt;
  
      &lt;!-- none of below works!! :( --&gt;
      &lt;a href="/{!cv.id}"&gt;{!cv.title} {!cv.pathOnClient}&lt;/a&gt;
      &lt;a href="https://na7.salesforce.com/069A00000009FG4"&gt;&lt;/a&gt;
      &lt;apex:image value="/069A00000009Ux3" width="220" height="55"/&gt;
  
  &lt;/apex:page&gt;
  </code></pre>