1

I have one problem during I try to upload photo to app/static/avatars folder in python flask.

my folder structure:

Project/
       app/
           static/
                 avatars/
           Upload/
                 upload.py

my destination folder is "avatars" and my codes is in "Upload/upload.py" How could I get realpath to upload?

Sample codes

UPLOAD_FOLDER                       =   'app/static/avatars/'
ALLOWED_EXTENSIONS                  =   set(['png', 'jpg', 'jpeg', 'gif'])
app.config['UPLOAD_FOLDER']         =   UPLOAD_FOLDER
app.config['MAX_CONTENT_LENGTH']    =   1 * 600 * 600

Error Message:

IOError: [Errno 2] No such file or directory: u'//app/static/avatars/002.png'

Thanks in advance!!

Mr Theavuth
  • 106
  • 1
  • 3
  • 11

1 Answers1

0

Okay, in upload.py you could do something like

>>> import os
>>> absolute_path = os.path.abspath("../"+UPLOAD_FOLDER+file_name)

os.path.abspath returns the absolute path from the given relative path, starting in your current working directory.

Timo Hanisch
  • 224
  • 1
  • 7