fix: Supabase storage upload hatasını çözmek için dosya adlarındaki Türkçe karakterler ve boşluklar temizlendi
This commit is contained in:
@@ -389,7 +389,13 @@ export const uploadDocument = async (req: AuthenticatedRequest, res: Response) =
|
||||
}
|
||||
|
||||
// 2. Upload File to Supabase Storage
|
||||
const filePath = `${user_id}/${Date.now()}_${file.originalname}`;
|
||||
const sanitizeFilename = (name: string) => {
|
||||
const charMap: Record<string, string> = { 'ç': 'c', 'ğ': 'g', 'ı': 'i', 'ö': 'o', 'ş': 's', 'ü': 'u', 'Ç': 'C', 'Ğ': 'G', 'İ': 'I', 'Ö': 'O', 'Ş': 'S', 'Ü': 'U' };
|
||||
const engName = name.replace(/[çğıöşüÇĞİÖŞÜ]/g, m => charMap[m]);
|
||||
return engName.replace(/[^a-zA-Z0-9.\-_]/g, '_');
|
||||
};
|
||||
const safeName = sanitizeFilename(file.originalname);
|
||||
const filePath = `${user_id}/${Date.now()}_${safeName}`;
|
||||
const { error: uploadError } = await supabase.storage
|
||||
.from('case-documents')
|
||||
.upload(filePath, file.buffer, {
|
||||
|
||||
@@ -29,7 +29,14 @@ export const uploadTemplate = async (req: AuthenticatedRequest, res: Response) =
|
||||
console.error('Template Text Extraction Error:', err);
|
||||
}
|
||||
|
||||
const storagePath = `templates/${userId}/${Date.now()}_${file.originalname}`;
|
||||
const sanitizeFilename = (name: string) => {
|
||||
const charMap: Record<string, string> = { 'ç': 'c', 'ğ': 'g', 'ı': 'i', 'ö': 'o', 'ş': 's', 'ü': 'u', 'Ç': 'C', 'Ğ': 'G', 'İ': 'I', 'Ö': 'O', 'Ş': 'S', 'Ü': 'U' };
|
||||
const engName = name.replace(/[çğıöşüÇĞİÖŞÜ]/g, m => charMap[m]);
|
||||
return engName.replace(/[^a-zA-Z0-9.\-_]/g, '_');
|
||||
};
|
||||
|
||||
const safeName = sanitizeFilename(file.originalname);
|
||||
const storagePath = `templates/${userId}/${Date.now()}_${safeName}`;
|
||||
const { error: uploadError } = await supabase.storage
|
||||
.from('case-documents')
|
||||
.upload(storagePath, file.buffer, { contentType: file.mimetype });
|
||||
|
||||
Reference in New Issue
Block a user