Skip to content

Commit 2e43683

Browse files
authored
Fix duplicate file upload
Currently, we face an issue when a file with the same name is uploaded more than once: 1.⁠ ⁠It results in a unique key error in the database. 2.⁠ ⁠If the file is sent to S3, it overwrites the old file. To resolve this problem, I've implemented a solution where we concatenate the message ID to the filename. This approach ensures uniqueness for each uploaded file, even if users upload files with identical names multiple times in a chat. This change allows normal users to upload files with the same name multiple times in a chat without encountering errors or unintended file overwrites.
1 parent ebbba7b commit 2e43683

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1992,7 +1992,7 @@ export class BaileysStartupService extends ChannelStartupService {
19921992

19931993
const mimetype = mime.getType(fileName).toString();
19941994

1995-
const fullName = join(`${this.instance.id}`, messageRaw.key.remoteJid, mediaType, fileName);
1995+
const fullName = join(`${this.instance.id}`, messageRaw.key.remoteJid, `${messageRaw.key.id}`, mediaType, fileName);
19961996

19971997
await s3Service.uploadFile(fullName, buffer, size.fileLength?.low, {
19981998
'Content-Type': mimetype,

0 commit comments

Comments
 (0)