title: Flask and sqlalchemy: Get uploaded file using path stored on database
body: <p>I'm using flask and sqlalchemy and I'm having issues regarding file uploading.</p>
  
  <p>I'm uploading the file with a form and storing the URL to the DB, so I can display it inside  on the page.</p>
  
  <p>Here's the form's code:</p>
  
  <pre><code>        boxart = request.files['boxart']
  
          if boxart:
              filename = secure_filename(boxart.filename)
              boxart_path = os.path.join(app.config['UPLOAD_FOLDER']+"boxart/", filename)
              boxart.save(boxart_path)
              game_son.boxart = boxart_path
  
          db.session.add(game_son)
          db.session.commit()
  </code></pre>
  
  <p>So I go to my template and I can print the content of game_son.boxart and there is the full path to the file. If I click on the link, I can access, but the image will not display inside  tag... </p>
  
  <p>I tried getting it on the template by using:</p>
  
  <pre><code>    &lt;img src="{{ game_son.boxart_url() }}" /&gt;
  </code></pre>
  
  <p>Inside the model, I defined a boxart_url method, in case I need to parse the string before sending it</p>
  
  <pre><code>  class Game_son(db.Model):
      __searchable__ = ['version_name']
      son_id = db.Column(db.Integer, primary_key=True)
      version_name = db.Column(db.String(128), index=True, unique=False)
      son_timestamp = db.Column(db.DateTime)
      dad = db.Column(db.Integer, db.ForeignKey('game_dad.id'))
      console = db.Column(db.Integer, db.ForeignKey('platform.id'))
      boxart = db.Column(db.String(256))
      thumbnail = db.Column(db.String(256))
      genre = db.Column(db.String(32))
      subgenre = db.Column(db.String(32))
  
      def boxart_url(self):
          return self.boxart 
  
      def __repr__(self):
          return '&lt;Game %r&gt;: %r' % (self.version_name, self.dad)
  </code></pre>
  
  <p>The page's view just send the entire object (game) to the page.</p>
  
  <p>The url that is arriving on the page is:</p>
  
  <p>/home/removed_my_pc_user/app/media/boxart/image.jpg</p>
  
  <p><strong>Edit:</strong>
  I just remembered that I'm using a virtual environment on the project.</p>
  
  <p>Is it related to chmod?</p>
  
  <p>Thanks in advance!!</p>