There is a content type field on the sys_attachment records that indicate the mimetype of the base64 you decode.  



Some examples:



Content type                 | File extension


application/pdf             | pdf


image/png                         | png