-
Notifications
You must be signed in to change notification settings - Fork 7.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MM-38982: fixes SVG uploading #20141
Conversation
Uploading SVG files was "almost" treated like an image in some places, resulting in not showing the SVG on the client. This is happening because when we fail to generate a mini preview for an image, we prepend "invalid-" to the MimeType. This commit adds a check to guard against SVG files in methods that make no sense for SVGs.
No Kubernetes clusters available at the moment, please contact the Mattermost Cloud Team or wait a bit. |
That's true, but also some methods are too specific for images, that assume a |
@streamer45 I think you're right, #18445 was a bit of a temporary fix to try to stop community from getting OOM. I'm not sure of the final result of that investigation, or whether we can remove the fix yet. |
@cpoile not that the app is going to crash without the changes, but IMO, yes either way these changes would be good to have e.g the following makes no sense for SVGs, does it? if info.IsImage() {
if limitErr := checkImageResolutionLimit(info.Width, info.Height, *a.Config().FileSettings.MaxImageResolution); limitErr != nil {
return nil, model.NewAppError("uploadData", "app.upload.upload_data.large_image.app_error",
map[string]interface{}{"Filename": us.Filename, "Width": info.Width, "Height": info.Height}, "", http.StatusBadRequest)
}
nameWithoutExtension := info.Name[:strings.LastIndex(info.Name, ".")]
info.PreviewPath = filepath.Dir(info.Path) + "/" + nameWithoutExtension + "_preview.jpg"
info.ThumbnailPath = filepath.Dir(info.Path) + "/" + nameWithoutExtension + "_thumb.jpg"
imgData, fileErr := a.ReadFile(uploadPath)
if fileErr != nil {
return nil, fileErr
}
a.HandleImages([]string{info.PreviewPath}, []string{info.ThumbnailPath}, [][]byte{imgData})
} I've also considered to change |
@agnivade Do you have more context on the original OOM issue that caused some of this code to be introduced? |
Yeah, the original OOM issue was due to passing the image preview as part of *model.Post to all plugins. Therefore, serializing the huge byte slice caused a large allocation. Then there was another unrelated issue caused by a model API change, but that didn't cause any memory problem. We can revert this one if it does not make sense any more. |
I'll defer to Claudio/CPoile on this. |
@koox00 I think we can remove the "invalid" mime type fix on top of this PR and proceed. |
@streamer45 done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @koox00 !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a couple more places where we check against image/svg+xml
. I'd suggest using the nice util you added here. Other than that, it looks great, thanks 👍
@koox00 Sometimes when I add a single .svg file it is not shown, but if the file is part of multi-attachment post it is shown. |
The previews are shown now, right? I assumed the posts in both screenshots are the same (the timestamp matches): |
@koox00 I still don't see the single svg posts on Chrome and Safari. They are visible on Firefox |
@jgilliam17 OK the issue for not showing are CSS rules, (which this PR doesn't change). |
@koox00 do we have to wait for webapp PR before merging this one? |
@jgilliam17 we can merge this one, and fix the webapp in another one |
Just waiting for E2Es to finish, will merge after report posts and if everything looks good. |
@jgilliam17 I've added this ticket for webapp https://mattermost.atlassian.net/browse/MM-44470 |
E2E report looks good. |
Test server destroyed |
* MM-38982: fixes SVG uploading Uploading SVG files was "almost" treated like an image in some places, resulting in not showing the SVG on the client. This is happening because when we fail to generate a mini preview for an image, we prepend "invalid-" to the MimeType. This commit adds a check to guard against SVG files in methods that make no sense for SVGs. * Reverts invalid-{mimetype} fix * Uses fileInfo.IsSvg() where it can
Summary
Uploading SVG files was "almost" treated like an image in some places,
resulting in not showing the SVG on the client.
This is happening because when we fail to generate a mini preview for an
image, we prepend "invalid-" to the MimeType.
This commit adds a check to guard against SVG files in methods that make
no sense for SVGs.
Ticket Link
https://mattermost.atlassian.net/browse/MM-38982
Release Note