Skip to content

fix(issues): Properly display image with mimetype octet stream #93359

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

Merged
merged 2 commits into from
Jun 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,42 +1,64 @@
import ImageViewer from 'sentry/components/events/attachmentViewers/imageViewer';
import JsonViewer from 'sentry/components/events/attachmentViewers/jsonViewer';
import LogFileViewer from 'sentry/components/events/attachmentViewers/logFileViewer';
import RRWebJsonViewer from 'sentry/components/events/attachmentViewers/rrwebJsonViewer';
import type RRWebJsonViewer from 'sentry/components/events/attachmentViewers/rrwebJsonViewer';
import {WebMViewer} from 'sentry/components/events/attachmentViewers/webmViewer';
import type {IssueAttachment} from 'sentry/types/group';

export const getInlineAttachmentRenderer = (
attachment: IssueAttachment
):
export const imageMimeTypes = [
'application/octet-stream',
'image/jpeg',
'image/png',
'image/gif',
'image/webp',
];

const logFileMimeTypes = [
'text/css',
'text/csv',
'text/html',
'text/javascript',
'text/plain',
];

const jsonMimeTypes = [
'application/json',
'application/ld+json',
'text/json',
'text/x-json',
];

export const webmMimeType = 'video/webm';

type AttachmentRenderer =
| typeof ImageViewer
| typeof LogFileViewer
| typeof RRWebJsonViewer
| typeof WebMViewer
| undefined => {
switch (attachment.mimetype) {
case 'text/css':
case 'text/csv':
case 'text/html':
case 'text/javascript':
case 'text/plain':
return attachment.size > 0 ? LogFileViewer : undefined;
case 'application/json':
case 'application/ld+json':
case 'text/json':
case 'text/x-json':
if (attachment.name === 'rrweb.json' || attachment.name.startsWith('rrweb-')) {
return RRWebJsonViewer;
}
return JsonViewer;
case 'image/jpeg':
case 'image/png':
case 'image/gif':
return ImageViewer;
case 'video/webm':
return WebMViewer;
default:
return undefined;
| typeof WebMViewer;

export const getInlineAttachmentRenderer = (
attachment: IssueAttachment
): AttachmentRenderer | undefined => {
if (imageMimeTypes.includes(attachment.mimetype)) {
return ImageViewer;
}

if (logFileMimeTypes.includes(attachment.mimetype)) {
return LogFileViewer;
}

if (
(jsonMimeTypes.includes(attachment.mimetype) && attachment.name === 'rrweb.json') ||
attachment.name.startsWith('rrweb-')
) {
return JsonViewer;
}

if (webmMimeType === attachment.mimetype) {
return WebMViewer;
}

return undefined;
};

export const hasInlineAttachmentRenderer = (attachment: IssueAttachment): boolean => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import {openConfirmModal} from 'sentry/components/confirm';
import {Button} from 'sentry/components/core/button';
import {ButtonBar} from 'sentry/components/core/button/buttonBar';
import {DropdownMenu} from 'sentry/components/dropdownMenu';
import {getInlineAttachmentRenderer} from 'sentry/components/events/attachmentViewers/previewAttachmentTypes';
import {
getInlineAttachmentRenderer,
imageMimeTypes,
webmMimeType,
} from 'sentry/components/events/attachmentViewers/previewAttachmentTypes';
import LoadingIndicator from 'sentry/components/loadingIndicator';
import Panel from 'sentry/components/panels/panel';
import PanelBody from 'sentry/components/panels/panelBody';
Expand Down Expand Up @@ -37,14 +41,6 @@ type Props = {
onlyRenderScreenshot?: boolean;
};

const loadingMimeTypes = [
'image/jpeg',
'image/png',
'image/gif',
'image/webp',
'video/webm',
];

function Screenshot({
eventId,
organization,
Expand All @@ -59,9 +55,13 @@ function Screenshot({
openVisualizationModal,
}: Props) {
const [loadingImage, setLoadingImage] = useState(
loadingMimeTypes.includes(screenshot.mimetype)
imageMimeTypes.includes(screenshot.mimetype) || webmMimeType === screenshot.mimetype
);

const {hasRole} = useRole({role: 'attachmentsRole'});
if (!hasRole) {
return null;
}

function handleDelete(screenshotAttachmentId: string) {
trackAnalytics('issue_details.issue_tab.screenshot_dropdown_deleted', {
Expand All @@ -70,10 +70,6 @@ function Screenshot({
onDelete(screenshotAttachmentId);
}

if (!hasRole) {
return null;
}

function renderContent(screenshotAttachment: EventAttachment) {
const AttachmentComponent = getInlineAttachmentRenderer(screenshotAttachment)!;

Expand Down Expand Up @@ -182,10 +178,6 @@ function Screenshot({
);
}

if (!hasRole) {
return null;
}

return <StyledPanel>{renderContent(screenshot)}</StyledPanel>;
}

Expand Down
Loading