Skip to content

Commit

Permalink
fix: filenames
Browse files Browse the repository at this point in the history
  • Loading branch information
santhoshvai committed Nov 23, 2023
1 parent b722859 commit e5ddb40
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package/src/components/Channel/Channel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1306,14 +1306,14 @@ const ChannelWithContext = <
isLocalUrl(attachment.image_url)
) {
const filename = file.name ?? file.uri.replace(/^(file:\/\/|content:\/\/)/, '');
// if any upload is in progress, cancel it
const controller = uploadAbortControllerRef.current.get(filename);
if (controller) {
controller.abort();
uploadAbortControllerRef.current.delete(filename);
}
const contentType = lookup(filename) || 'multipart/form-data';

// if any upload is in progress, cancel it
const uploadResponse = doImageUploadRequest
? await doImageUploadRequest(file, channel)
: await channel.sendImage(file.uri, filename, contentType);
Expand Down
15 changes: 10 additions & 5 deletions package/src/contexts/messageInputContext/MessageInputContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -641,20 +641,25 @@ export const MessageInputProvider = <
setText('');
};

const mapImageUploadToAttachment = (image: ImageUpload) => {
const mapImageUploadToAttachment = (image: ImageUpload): Attachment<StreamChatGenerics> => {
const mime_type: string | boolean = lookup(image.file.filename as string);
const name = image.file.name ?? (image.file.filename as string);
return {
fallback: image.file.name,
fallback: name,
image_url: image.url,
mime_type: mime_type ? mime_type : undefined,
original_height: image.height,
original_width: image.width,
originalFile: image.file,
originalFile: {
...image.file,
duration: image.file.duration ? `${image.file.duration}` : undefined,
name,
},
type: 'image',
} as Attachment;
};
};

const mapFileUploadToAttachment = (file: FileUpload) => {
const mapFileUploadToAttachment = (file: FileUpload): Attachment<StreamChatGenerics> => {
if (file.file.mimeType?.startsWith('image/')) {
return {
fallback: file.file.name,
Expand Down

0 comments on commit e5ddb40

Please sign in to comment.