Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
467c848
fix: image upload failing for specific jpegs
cardoso Apr 17, 2025
e35a9f2
Merge branch 'develop' into SUP-769-Image-Upload-Display-Error-Messag…
cardoso Apr 20, 2025
ef168d3
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
cardoso Apr 21, 2025
1216317
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
cardoso Apr 22, 2025
ad646da
fix: display error indicator when image upload fails
cardoso Apr 22, 2025
36c44ad
test: with and without Message_Attachments_Strip_Exif
cardoso Apr 22, 2025
0fee022
Merge branch 'develop' into SUP-769-Image-Upload-Display-Error-Messag…
cardoso Apr 24, 2025
86a7e82
chore: add changeset
cardoso Apr 24, 2025
8545447
Merge branch 'develop' into SUP-769-Image-Upload-Display-Error-Messag…
cardoso Apr 24, 2025
ca4c75c
Merge branch 'develop' into SUP-769-Image-Upload-Display-Error-Messag…
cardoso Apr 25, 2025
a90d908
Merge branch 'develop' into SUP-769-Image-Upload-Display-Error-Messag…
cardoso Apr 29, 2025
3d68509
Merge branch 'develop' into SUP-769-Image-Upload-Display-Error-Messag…
cardoso Apr 29, 2025
5d41a4b
Merge branch 'develop' into SUP-769-Image-Upload-Display-Error-Messag…
cardoso Apr 30, 2025
ba30030
Merge branch 'develop' into SUP-769-Image-Upload-Display-Error-Messag…
cardoso May 7, 2025
7c96888
fix: handle possible empty string
cardoso May 7, 2025
e3caef8
fix: handle possible empty string
cardoso May 7, 2025
eca914b
fix: handle error response for file upload in send function
cardoso May 7, 2025
04c87e2
fix: UploadProgressIndicator a11y
dougfabris May 8, 2025
525b023
test: updates image upload error selector
cardoso May 8, 2025
e26d291
fix: review
dougfabris May 8, 2025
f893616
Merge branch 'develop' into SUP-769-Image-Upload-Display-Error-Messag…
kodiakhq[bot] May 9, 2025
bff8ede
Merge branch 'develop' into SUP-769-Image-Upload-Display-Error-Messag…
kodiakhq[bot] May 9, 2025
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
5 changes: 5 additions & 0 deletions .changeset/rare-mails-whisper.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

Fixes an issue where the upload of malformed images failed silently with Message_Attachments_Strip_Exif disabled
47 changes: 27 additions & 20 deletions apps/meteor/client/lib/chats/uploads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,13 @@ const send = async (
): Promise<void> => {
const id = Random.id();

updateUploads((uploads) => [
...uploads,
{
id,
name: fileContent?.raw.name || file.name,
percentage: 0,
},
]);
const upload: Upload = {
id,
name: fileContent?.raw.name || file.name,
percentage: 0,
};

updateUploads((uploads) => [...uploads, upload]);

try {
await new Promise((resolve, reject) => {
Expand Down Expand Up @@ -114,20 +113,28 @@ const send = async (
);

xhr.onload = async () => {
if (xhr.readyState === xhr.DONE && xhr.status === 200) {
const result = JSON.parse(xhr.responseText);
let content;
if (getContent) {
content = await getContent(result.file._id, result.file.url);
if (xhr.readyState === xhr.DONE) {
if (xhr.status === 400) {
const error = JSON.parse(xhr.responseText);
updateUploads((uploads) => [...uploads, { ...upload, error: new Error(error.error) }]);
return;
}

await sdk.rest.post(`/v1/rooms.mediaConfirm/${rid}/${result.file._id}`, {
msg,
tmid,
description,
t,
content,
});
if (xhr.status === 200) {
const result = JSON.parse(xhr.responseText);
let content;
if (getContent) {
content = await getContent(result.file._id, result.file.url);
}

await sdk.rest.post(`/v1/rooms.mediaConfirm/${rid}/${result.file._id}`, {
msg,
tmid,
description,
t,
content,
});
}
}
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { css } from '@rocket.chat/css-in-js';
import { Box, Button, Palette } from '@rocket.chat/fuselage';
import type { ReactElement } from 'react';
import { useCallback } from 'react';
import { useCallback, useMemo } from 'react';
import { useTranslation } from 'react-i18next';

import type { Upload } from '../../../../lib/chats/Upload';
Expand Down Expand Up @@ -34,6 +34,14 @@ const UploadProgressIndicator = ({ id, name, percentage, error, onClose }: Uploa
onClose?.(id);
}, [id, onClose]);

const uploadProgressTitle = useMemo(() => {
if (error) {
return `${error} ${name}`;
}

return `[${percentage}%] ${t('Uploading_file__fileName__', { fileName: name })}`;
}, [error, name, percentage, t]);

return (
<Box
pb={4}
Expand All @@ -52,8 +60,8 @@ const UploadProgressIndicator = ({ id, name, percentage, error, onClose }: Uploa
bg='surface-tint'
className={customClass}
>
<Box withTruncatedText zIndex={2} borderRadius={4}>
[{percentage}%] {name}
<Box role='status' withTruncatedText zIndex={2} borderRadius={4}>
{uploadProgressTitle}
</Box>
<Button zIndex={3} small onClick={handleCloseClick}>
{t('Cancel')}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
58 changes: 58 additions & 0 deletions apps/meteor/tests/e2e/image-upload.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { Users } from './fixtures/userStates';
import { HomeChannel } from './page-objects';
import { createTargetChannel, getSettingValueById, setSettingValueById } from './utils';
import { test, expect } from './utils/test';

test.use({ storageState: Users.user1.state });

test.describe('image-upload', () => {
let settingDefaultValue: unknown;
let poHomeChannel: HomeChannel;
let targetChannel: string;

test.beforeAll(async ({ api }) => {
settingDefaultValue = await getSettingValueById(api, 'Message_Attachments_Strip_Exif');
targetChannel = await createTargetChannel(api, { members: ['user1'] });
});

test.beforeEach(async ({ page }) => {
poHomeChannel = new HomeChannel(page);
await page.goto('/home');
await poHomeChannel.sidenav.openChat(targetChannel);
});

test.afterAll(async ({ api }) => {
await setSettingValueById(api, 'Message_Attachments_Strip_Exif', settingDefaultValue);
expect((await api.post('/channels.delete', { roomName: targetChannel })).status()).toBe(200);
});

test.describe('strip exif disabled', () => {
test.beforeAll(async ({ api }) => {
await setSettingValueById(api, 'Message_Attachments_Strip_Exif', false);
});

test('should show error indicator when upload fails', async () => {
await poHomeChannel.content.sendFileMessage('bad-orientation.jpeg');
await poHomeChannel.content.fileNameInput.fill('bad-orientation.jpeg');
await poHomeChannel.content.descriptionInput.fill('bad-orientation_description');
await poHomeChannel.content.btnModalConfirm.click();

await expect(poHomeChannel.statusUploadIndicator).toContainText('Error:');
});
});

test.describe('strip exif enabled', () => {
test.beforeAll(async ({ api }) => {
await setSettingValueById(api, 'Message_Attachments_Strip_Exif', true);
});

test('should succeed upload of bad-orientation.jpeg', async () => {
await poHomeChannel.content.sendFileMessage('bad-orientation.jpeg');
await poHomeChannel.content.fileNameInput.fill('bad-orientation.jpeg');
await poHomeChannel.content.descriptionInput.fill('bad-orientation_description');
await poHomeChannel.content.btnModalConfirm.click();

await expect(poHomeChannel.content.getFileDescription).toHaveText('bad-orientation_description');
});
});
});
4 changes: 4 additions & 0 deletions apps/meteor/tests/e2e/page-objects/home-channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,8 @@ export class HomeChannel {
get btnJoinRoom(): Locator {
return this.page.getByRole('button', { name: 'Join' });
}

get statusUploadIndicator(): Locator {
return this.page.getByRole('main').getByRole('status');
}
}
1 change: 1 addition & 0 deletions packages/i18n/src/locales/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -5295,6 +5295,7 @@
"Upload_private_app": "Upload private app",
"Upload_user_avatar": "Upload avatar",
"Uploading_file": "Uploading file...",
"Uploading_file__fileName__": "Uploading file {{fileName}}",
"Uploads": "Uploads",
"Uptime": "Uptime",
"Usage": "Usage",
Expand Down
Loading