- Whenever
a File type is present in request object, commerce ignores the rest of
parameters coming after that.
- The
inbuilt mechanism treats the file object as UploadedFile type object. This
type of object provides a limited number of options to further process the
File Objects.
File Upload Basic
Requirements
Request Parsing
To achieve this, we need to have HTTPRequest object. We can get it as below:
Configuring Request
Parser
To
parse the File Objects, Apache provides ServletFileUpload
class. Before it can be used, it needs to be initialized with a DiskFileItemFactory
object. And we want to configure this factory before handing over to
ServletFileUpload class.So we need to provide the Temporary location where it can save the items. And apart from that we need to set the maximum File size limit.
If the File object in request exceeds the max size, a FileUploadException is thrown.
Building the Request
Properties
Once
we have set everything, we need to get the FileItem from request and rebuild
the request properties as below:
Save Image
Before we actually save the file we need to set the file permission as below:
Ajax like File Upload
Related links
Disk File Item: DiskFileItemFactory
Servlet File Upload: ServletFileUpload
Multipart Form: W3 Multipart
Ajax like File upload using dojo.io.iframe utility : dojo wiki, dojo documentation
Comments
Post a Comment