mirror of
https://github.com/discourse/discourse.git
synced 2025-05-28 13:51:18 +08:00
FIX: Pass upload type correctly to uploads#create (#29600)
Prior to Uppy, the `uploads#create` endpoint used to receive a `type` param that indicated the purpose/target of the upload, such as `avatar`, `site_setting` and so on. With the introduction of Uppy, the `type` param became the MIME type of the file being uploaded, and the purpose/target of the upload became a new param called `upload_type`, however the backend could still use the `type` param (which now contains MIME type) as the purpose/target of the upload if `upload_type` is absent.
We technically don't need to send the MIME type over the network, but it seems like it's done by Uppy and we have no control over the `type` param that Uppy includes:
758de8167b/app/assets/javascripts/discourse/app/lib/uppy/uppy-upload.js (L146-L151)
This commit does a couple of things:
1. It amends the `uploads#create` endpoint so it always requires the `upload_type` param and doesn't fallback to `type` if `upload_type` is absent
2. It forces consumers of the `UppyUpload` class (and by extension `UppyImageUploader`) to specify `type` of the upload
Internal topic: t/140945.
This commit is contained in:
@ -32,11 +32,9 @@ class UploadsController < ApplicationController
|
||||
1.minute.to_i,
|
||||
).performed!
|
||||
|
||||
params.permit(:type, :upload_type)
|
||||
raise Discourse::InvalidParameters if params[:type].blank? && params[:upload_type].blank?
|
||||
params.require(:upload_type)
|
||||
# 50 characters ought to be enough for the upload type
|
||||
type =
|
||||
(params[:upload_type].presence || params[:type].presence).parameterize(separator: "_")[0..50]
|
||||
type = params[:upload_type].parameterize(separator: "_")[0..50]
|
||||
|
||||
if type == "avatar" &&
|
||||
(
|
||||
|
Reference in New Issue
Block a user