When using the Soap API to work with an Attachment how can I determine the correct file extension when saving the Body contents locally?
E.g.
I created a test attachment on an Account from a PDF. The default name field includes the file extension as it was uploaded. However, the user is free to edit this field and remove the ".pdf" suffix.
The ContentType field contains what I'd think of as the MIME type. I could maintain a mapping from the ContentType to the file extension, but the relationship isn't 1:1.
The following MIME types map to multiple possible file extensions:
- application/vnd.ms-excel - xls, xla, xlc, xlm, xlt, xlw
- application/postscript - ai, eps, ps
- application/vnd.ms-powerpoint - ppt, pot, pps
If I want to save the bytes pulled out of the Body field somewhere locally I can't determine the correct file extension to use if the user has edited the attachment name. I can make a reasonable guess, but it might not be correct. In some cases it may not be an issue, as the target application will still correctly interpret the file.