title: RESTful app backend: How to properly serve images from Google cloud storage?
body: <p>So, I'm building an android app which uses a RESTful API as it's backend. The intention to to use the API as a datasource for a future website as well, and possibly an IOS app.</p>
  
  <p>The api is built on Spring Boot and running on Heroku.</p>
  
  <p>I'm trying to figure the proper way to serve images from google cloud storage for my app, but I'm confused.</p>
  
  <p>I hava database table for user entities with columns such as email, name, etc., and one of these columns is supposed to hold a URI for their profile picture.</p>
  
  <p>I'm confused about how to do things from this point on in a proper restful manner. I've boiled my ideas down to this, but there are some problems:</p>
  
  <p><em>Uploading an image</em>:
  User makes a POST request to <code>users/{id}/profilepic</code> with a .jpg payload. The server then uploads the image (after possible validation/authentication) to google cloud storage, gets the URL for the image there and stores it in the database column.</p>
  
  <p><em>Retrieving an image</em>:
  User makes a GET request to <code>users/{id}/profilepic</code>. The server looks up the URI for their profile picture in the database, makes it's own request to the URI to retrive the image, and returns the image to the user as .jpg file (encoded how?).</p>
  
  <p><strong>Problem - Middleman inefficiency and authentication/access control</strong> - It seems a little redundant (and possibly slow) for the server to be a sort of middle man here, but I do see advantages to it. The alternative would be to send the frontend (app, website, etc.) the URL to the image and allows the frontend to retrieve it itself, but this would mean I have no control over  who can access the image.</p>
  
  <p>Is this a good model? How do I go about implementing it in code? Are there any tutorials that cover this?</p>