16 lines
451 B
Python
16 lines
451 B
Python
|
from flask import (current_app, send_from_directory)
|
||
|
from hashlib import sha1
|
||
|
from pathlib import Path
|
||
|
from os import path
|
||
|
|
||
|
def save(name, content):
|
||
|
h = sha1(content).hexdigest()
|
||
|
filename = h + Path(name).suffix
|
||
|
file = open(path.join(current_app.config['UPLOAD_FOLDER'], filename), "wb")
|
||
|
file.write(content)
|
||
|
file.close()
|
||
|
return filename
|
||
|
|
||
|
def get(name):
|
||
|
return send_from_directory(current_app.config["UPLOAD_FOLDER"], name)
|