     }
   }
 
+  // Get image binary.
+  // It does not seem technically possible to server attachments from Cloudant
+  // without requiring authentication. Hence, the need for this proxy method.
+  router.get("/images/:imageId/:attachmentName") { request, response, next in
+    guard let imageId = request.params["imageId"],
+    let attachmentName = request.params["attachmentName"] else {
+      response.error = generateInternalError()
+      next()
+      return
+    }
+
+    database.retrieveAttachment(imageId, attachmentName: attachmentName) { (image, error, contentType) in
+      if  let image = image where error == nil  {
+        if let contentType = contentType {
+          response.setHeader("Content-Type", value: contentType)
+        }
+        response.status(HttpStatusCode.OK).sendData(image)
+      }
+      else {
+        response.error = error ?? generateInternalError()
+      }
+      next()
+    }
+  }
+
   //////////////////////////////////////////////////////////////
-  //TODO: Validate need for these middlewares
-
-  //???
+  //TODO: Validate need for these middleware
+
+  //What is this doing?
   router.all("/photos/*", middleware: BodyParser())
 
-  // Needed for authentication
-  //router.post("/photos/:title/:photoname", middleware: credentials)
-
   /////////////////////////////////////////////////////////////
 
 }

import CouchDB
import LoggerAPI
import SwiftyJSON
//import Credentials

// Setup the handlers for the Photo APIs
func defineRoutes() {

    }
  }

  // Get a specific user document
  router.get("/users/:userId") { request, response, next in
    guard let userId = request.params["userId"] else {
      response.error = NSError(domain: BluePic.Domain, code: BluePic.Error.Internal.rawValue, userInfo: [NSLocalizedDescriptionKey: String(BluePic.Error.Internal)])
