title: How to get safe url for image in Flask?
body: <p>I have stored all images in folder <strong>\uploads</strong>. I have stored filename + extension in database. Each image has name <strong>PHOTO_ID.jpeg</strong>. I have some query on items and to those items I connect photo by its id. I want send JSON response something like this that contains url for image.</p>
  
  <p><strong>WANTED RESPONSE:</strong> <code>json:{name: 'somename' url: 'imageURL'}</code></p>
  
  <p>So question is <strong>how to get URL that can be accessible from one user only</strong>. I don't want to anybody be able to guess url of others image.
  I found some methods in FLASK but they need to be bind to some endpoint. I don't want explicit endpoint for retrieving url of images.
  These methods I found so far: </p>
  
  <pre><code>send_from_directory(DIRECTORY,FILENAME)
  url_for(endpoint, filename=filename)
  send_file(FILEPATH,'image/' + extension, as_attachment=True)
  </code></pre>
  
  <p>I want something simple like this <code>retrieve_url(FILEPATH)</code> that will return url and secure approach only for one user.</p>
  
  <p>Thank you for your help.</p>