2

I was looking for example to upload attachment via VF page.

There are multiple examples(similar code) available online, with some making use of enctype="multipart/form-data. While other directly proceeded without making use of it. For eg. http://www.forcetree.com/2011/02/upload-file-as-attachment-to-record.html ( no use of enctype)

(2) http://blog.jeffdouglas.com/2010/04/28/uploading-an-attachment-using-visualforce-and-a-custom-controller/ ( making use of enctype)

What is the best practice? when to use and when not?

Thanks !

2

Considering that multipart/form-data is the only 100% cross-browser compatible method of uploading files via POST, the enctype declaration is redundant at the moment. Of course, HTML5 has a shiny new file API, but first we need to wean everyone off of IE 9 and lower (not quite there yet!).

Both versions are likely identical in nature, at least today, but forcing an enctype might have future implications. When in doubt, don't use it. Doing so might require future maintenance, while not including it shouldn't.

You should only use enctype explicitly if something is broken, or you want to send data off salesforce. Unlike plain HTML, Visualforce already knows how to upload files to salesforce servers. No need to tell it what to do.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.