def upload():
from run import config
form = UploadForm()
if form.validate_on_submit():
# Process uploaded file
uploaded_file = request.files[form.file.name]
if uploaded_file:
filename = secure_filename(uploaded_file.filename)
temp_path = os.path.join(
config.get('SAMPLE_REPOSITORY', ''), 'TempFiles', filename)
# Save to temporary location
uploaded_file.save(temp_path)
# Get hash and check if it's already been submitted
file_hash = create_hash_for_sample(temp_path)
if sample_already_uploaded(file_hash):
# Remove existing file and notice user
os.remove(temp_path)
form.errors['file'] = [
'Sample with same hash already uploaded or queued']
else:
add_sample_to_queue(file_hash, temp_path, g.user.id, g.db)
# Redirect
return redirect(url_for('.index'))
return {
'form': form,
'accept': form.accept,
'upload_size': (config.get('MAX_CONTENT_LENGTH', 0) / (1024 * 1024)),
}
评论列表
文章目录