You need to sign in to do that
Don't have an account?
cbernal
Validate attachment's extension
Hi,
Anyone knows how to check the extension file for an attachment.
I have this Trigger:
trigger checkAttachment on Attachment (before insert) {
For(Attachment att:Trigger.new)
{
if(att.ContentType=='.exe')
{
att.addError('Cannot upload file with extension .exe');
}
}
}
But it don't work, it still accepts files with .exe extension.
The filed ContentType will contain the MIMEType of a file. So .EXE will be 'application/octet-stream', you can find a list of different MIMETypes online. Here's the first one I found on google. http://www.webmaster-toolkit.com/mime-types.shtml
You can also accomplish this by just checking your name of the file you uploaded IE: att.Name.endsWith('.exe')
All Answers
The filed ContentType will contain the MIMEType of a file. So .EXE will be 'application/octet-stream', you can find a list of different MIMETypes online. Here's the first one I found on google. http://www.webmaster-toolkit.com/mime-types.shtml
You can also accomplish this by just checking your name of the file you uploaded IE: att.Name.endsWith('.exe')
Thanks
I solved it with
but I still have to validate the .zip or .rar files with a .exe file.
Do you know how can I do it?
I believe APEX is currently unable to read/extract ZIP / RAR files natively.