Exemple #1
0
def save_file(file_obj, where='uploaded'):
    """
    Saves file to where directory on the server
    """
    # todo: check for errors, types or file_obj properties
    folder = os.path.join(config.ROOT_FOLDER, where)
    new_filename = unique_filename(file_obj.filename)
    file_path = os.path.join(folder, new_filename)
    with open(file_path, 'wb') as open_file:
        open_file.write(file_obj.file.read())
    return new_filename  # returns new filename
Exemple #2
0
def up_file():
    """
    Uploads a picture to the article
    """
    up_file = request.files.get('file')
    web_folder = 'img/article/'
    pictures_folder = static_path(web_folder)
    new_filename = unique_filename(up_file.filename)
    file_path = os.path.join(pictures_folder, new_filename)
    # todo: check for file existence
    # photo_file.save('/img/gallery/')  # new Bottle
    with open(file_path, 'wb') as open_file:
        open_file.write(up_file.file.read())
    return join_all_path(['/', web_folder, new_filename])