Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions succulent/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import xml.etree.ElementTree as ET
import pandas as pd
from datetime import datetime
from werkzeug.utils import secure_filename


class Processing:
Expand Down Expand Up @@ -216,12 +217,24 @@ def process(self, req):
# Retrieve image from request
file = req.files[self.key]

filename = secure_filename(file.filename or '')
if not filename:
filename = 'upload'

# Timestamp
timestamp = datetime.now().strftime('%Y-%m-%d_%H%M%S')

# Build the destination path and verify it stays within the target
# directory. ``secure_filename`` already prevents traversal; this
# check is defence in depth in case that behaviour ever changes.
directory = os.path.abspath(self.directory)
destination = os.path.abspath(
os.path.join(directory, f'{timestamp}_{filename}'))
if os.path.commonpath([directory, destination]) != directory:
raise ValueError('Invalid file path.')

# Store image to device
file.save(os.path.join(self.directory,
f'{timestamp}_{file.filename}'))
file.save(destination)

def data(self, req):
"""Generate results based on the stored data.
Expand Down
Loading