Created
November 11, 2024 19:41
-
-
Save Chippd/d7f0072e8d2bf89b1903078813dfc63e to your computer and use it in GitHub Desktop.
code sample of image deletion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// the actual fileId is in storage_data.fileId | |
const fileId = file.storage_data.fileId | |
console.log('fileId', fileId) | |
// Delete the file from ImageKit | |
try { | |
// Wrap the callback-based function in a Promise | |
await new Promise((resolve, reject) => { | |
imageKit.deleteFile(fileId, (error, result) => { | |
if (error) { | |
console.error('ImageKit deletion error:', error); | |
reject(error); | |
return; | |
} | |
resolve(result); | |
}); | |
}); | |
// Delete the record from the database | |
const { error: deleteError } = await supabase | |
.from('enterprise_media') | |
.delete() | |
.eq('file_name', body.fileName); | |
if (deleteError) { | |
throw createError({ | |
statusCode: 500, | |
statusMessage: 'Error deleting file record from database' | |
}); | |
} | |
return { | |
success: true, | |
message: 'File deleted successfully' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment