feat: add support for uploading images via blazor method or controller. #17
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This may resolve #10, but this might not be exactly what you had in mind. Regardless, I added the ability to upload images via a Blazor method, or a controller action. After uploading, the images get inserted as an
img
tag with thesrc
attribute set to the path of the uploaded image. This is something I need for my project, so I went ahead and fixed it myself. The base64 encoding behavior continues to be enabled by default - this server-side uploading feature must be configured by the user.In the
MudHtmlEditor.razor.cs
file, I added three new parameters and one new method. Also, I added asettings
object to group the existingplaceholder
setting with the new ones I added before they get passed via interop to the JS side of the component.In
MudHtmlEditor.razor.js
, I addeduploadImageHandler
- a custom handler for the (unfortunately undocumented) quill uploader module - and a supportingupload
function which does the actual upload to the server.In the remaining files, I prepared an example controller method and Blazor method that will upload the image to the
wwwroot/images
folder on the server, and return a url likeimages/image.png
as the response for the JS to pick back up so it can insert that url as part of the resultingimg
tag.