Skip to content

Commit

Permalink
Add check to upload CSV file's content-type.
Browse files Browse the repository at this point in the history
  • Loading branch information
Faakhir30 committed Sep 30, 2024
1 parent 3361b58 commit 2ac7b4f
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/plone/restapi/services/aliases/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,19 @@ def _reply_csv(self):
form = self.request.form
if not form.get("file"):
raise BadRequest("No file uploaded")

file = form["file"]

if not hasattr(file, "headers"):
raise BadRequest("Uploaded file is not a valid file")
if file.headers.get("Content-Type") not in ("text/csv", "application/csv"):
raise BadRequest("Uploaded file is not a valid CSV file")

controlpanel = RedirectsControlPanel(self.context, self.request)
storage = getUtility(IRedirectionStorage)
status = IStatusMessage(self.request)
portal = getSite()
file = form["file"]

controlpanel.upload(file, portal, storage, status)
file.close()

Expand Down

0 comments on commit 2ac7b4f

Please sign in to comment.