#Validate .doc .pdf files. Accept pdf file uploads securely?

3 messages · Page 1 of 1 (latest)

hollow urchin
#

Hi guys I need to accept .doc and .pdf files (candidate CVs) are there any libraries to safely validate? Are there any simple approaches to this? Any recommendations? Bit lost with how to deal with this

jolly magnet
#

You'll need to do content type detection, sometimes called MIME detection. The stdlib http package has DetectContentType which may do pdf, might not do word document though. There are other libraries that use libmagic and C bindings (the same lib that the file utility uses for determining file type), or pure Go solutions

#

You should also validate the extension, and uniquely name the file (with a uuid for example) if it's going into the filesystem, and disregard the original file name from the user entirely.