Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Web CMS (TeamSite)
upload file to livesite component
niske
We have built a livesite form component, where business users can create their own forms (which are then wrapped into an email message and sent). Now we want to add a file upload option to this (so that the visitor to the website can upload a file in the form). This file should be uploaded and then sent with the email as an attachment.
But we cannot seem to upload the file with standard Livesite functionality.
Any ideas if it is possible and that we are overlooking something?
thanks
Find more posts tagged with
Comments
tec_iwov
can you elaborate,
what version of livesite?
What errors are you getting if any?
are you using any special library to handle the multipart form to
extract the file?
flivauda
if you add Type="External" to your form tag LiveSite will leave the form totally alone and then you can submit to a different .jsp page that handles the file uploading in a standard way. You'll need to make sure you have a multi-part (ENCTYPE="multipart/form-data") form.
sanoboy
Now i'm also facing this problem.
Yes, we need set form enctype="multipart/form-data", and i try to get file from the request in java class and then upload to the server, but the tag i set isMultipart = ServletFileUpload.isMultipartContent(context.getRequest) always get false. Am i wrong using this method?
AlexC
We do not fully support multi-part forms at this point out of the box.
You would have to add a servlet to the livesite context that calls the multi-part form parser and extracts your file and saves it, the RequestContext will not be available only the standard HTTP request and response objects. You may also be able to insert a filter that detects the multipart and parses it before continuing with the rendering of the page.
Both of these methods will require custom code, the servlet one is simpler in my opinion as it would simply require a change to web.xml and java code to handle the parsing.
You can also try parsing the input using a component and external, but I do not know how the post data is handled by the framework. type='external' simply lets you add your own parameters to the submit without livesite modifying them.
The reason for not providing this out of the box is prevention of DOS (denial of service) attacks, if someone uploads an extremely large file they can render the server unusable, so whatever processes the upload must have limits built it to close the connection during read on unreasonably long files.
If you are using SitePub/Livesite 6.7.2sp2 or newer you can use following to set the form as multipart:
[html]
More stuff here
[/html]
Binettoid
Thanks for this snippet of info, Alex! If you could elaborate on how you sugges tadding the entries to web.xml and then how you would call this upload procedure from within a controller, I would be most grateful.
Has anyone had any success doing this with the included org.apache.commons.fileupload package or similar?
Or any other way? I'm trying to do this using commons fileupload from within a controller, but not having any luck so far. Any tips would be greatly apprec iated.
Faizi
Does anyone implemented file uploading functionality in LiveSite? Please share your view points.
I tried to implement same way as Alex mentioned in his post. But Servlet methods doPost() or doGet() was not invoking. While init() is called at once.
Please give some pointer here.
Thanks in Advance.
Binettoid
We got this to work by building a stand-alone servlet. The form does not submit to a LiveSite controller at all, but simply to the servlet, as defined in the web.xml. This may mean you have to move other functionality into this servlet, e.g. update DB records, send email, etc.
This is how our working form looks:
[HTML]
[/HTML]
N.B. /upload/upload.html does not exist, but this is the mapping for the servlet defined in web.xml. We also found it useful to include hidden form fields containing the success and failure URLs, that are parameters defined in the component, so that business users can redefine these from the component properties interface.