Way to map drag and drop uploads to a configured media type #13721
Replies: 6 comments 1 reply
-
Hi @enkelmedia, I will admit, I read this 3 times and I'm not understanding what you're trying to achieve. 🙈 What is your use case, what is currently impossible that this change would allow you/others to do? |
Beta Was this translation helpful? Give feedback.
-
hehe sorry! I'll try to make it more clear =D There is a feature where one can just drag and drop files to upload them to the media-section, implemented in the "umb-file-dropzone"-directive. This feature posts the file to /umbraco/backoffice/UmbracoApi/Media/PostAddFile The request body looks something like this
Inside the MediaControllers PostAddFile-method: The contentTypeAlias "umbracoAutoSelect" means that Umbraco will use "File" as the default media type alias for the uploaded file. If the extension is any of the known image-extensions Umbraco will use "Image" as media type. Otherwise it will use the media type "File" (all which are hardcoded). In our case we have created a custom media type for videos, what I'm proposing is a way to map ie a ".mp4"-file to this custom type when it's uploaded. Is in the MediaController around L707 I'm thinking that we could add a collection of "mappings" between file extensions and media types. So that the code would look both in the known image types and in this collection of configured mappings, so when a editor drags in a .mp4 file it would be created as a "video" and not as a "file". I just proposed a collection builder to be able to append/change the mappings. So I'm thinking that we could:
public class VideoMediaMap : IMediaMap {
public string[] Extensions => new string[]{"mp4","mov"};
public string ContentTypeAlias => "video";
}
Hope this makes it more clear =D |
Beta Was this translation helpful? Give feedback.
-
It would also be great if this took into account restrictions on the parent folder. There are cases where you need multiple "pdf" definitions due to different CMS data linked to a file. |
Beta Was this translation helpful? Give feedback.
-
Sounds like a great feature request, moving this to discussions 👍 |
Beta Was this translation helpful? Give feedback.
-
I think being able to map extensions to MediaTypes for the drag-n-drop is a GREAT idea. +💯 It would also give us an easy way to customize the types which are considered "Image" (rather than relying on the hard-coded Configuration) |
Beta Was this translation helpful? Give feedback.
-
Hi @iOvergaard - I actually came upon this discussion while working on an upgrade project for a client. Reviewing their Media section (which has been growing since v7, I admit) I came across some media which were added as Files, whereas they should be Images. I know that new file formats sometimes arise, and I think the few "webp" images in the Media section were likely added prior to that being widely recognized - and thus they were not recognized as Images. I was curious to know which extensions would be considered images, (specifically for the drag-n-drop - which I know is a popular way to add files quickly to the Media section) and whether that was configurable for handling new formats as they arise (or perhaps more obscure formats), additionally, it's possible that a developer would want to encourage the use of certain formats for on-site images (or discourage other formats), and thus it isn't crazy to think this should be somehow configurable, rather than hard-coded in source. For my purposes, even a simple AppSettings config option would be fine. As your video demonstrates, the "Upload" property type allows defining the extensions accepted, but this is not the case with the "Image Cropper" type. |
Beta Was this translation helpful? Give feedback.
-
We're using some custom media types, most of the time a video-media type.
When someone drags and drops ie a .mov or .mp4-file it gets the "umbracoAutoSelect" document type and are sent to the PostAddFile()-file method on the MediaController.
Inside this method we're comparing the extension against known image types and otherwise we're using the "File" media type as a fallback.
It would be useful to be able to hook in here and setup a mapping between file extensions and media types, something that could be configured during startup, maybe using a collection builder or something.
Is this something that you would consider?
Beta Was this translation helpful? Give feedback.
All reactions