In developer life, to stuck at any point is routine. here is one of the point i am sharing where many of us stuck and it's take lot more times to come out with solution.
Scenario: upload file with Ajax.
Some time we need to upload(by file) some data and process them. but after finished data process page doesn't refreshed. to achieve this we defiantly use Ajax. so, generally we giving <portlet:resourceURL> in form action. form which include input file object. here in this case, if we submit the form and try to get uploaded file in liferay controller. it's doesn't work because of ajax. your serverResource() of portlet controller is not able to fetch file object from request. because ajax request generally we are passing String & Number data. but this is File so ajax can not handle this tyep of data. after trying more and giving lot more time to resolve this. i found resolution that what i am going to share here....
$.ajaxFileUpload
alert("File upload success")
return false;
UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(resourceRequest);
Scenario: upload file with Ajax.
Some time we need to upload(by file) some data and process them. but after finished data process page doesn't refreshed. to achieve this we defiantly use Ajax. so, generally we giving <portlet:resourceURL> in form action. form which include input file object. here in this case, if we submit the form and try to get uploaded file in liferay controller. it's doesn't work because of ajax. your serverResource() of portlet controller is not able to fetch file object from request. because ajax request generally we are passing String & Number data. but this is File so ajax can not handle this tyep of data. after trying more and giving lot more time to resolve this. i found resolution that what i am going to share here....
if multiple files are uploaded then what should be the value of fileElementId
ReplyDeleteThanks For this informative post. Just small change , instead of File file = uploadRequest.getFile("fileUpload"); change with File file = uploadRequest.getFile("file"); as input type name is "file"
ReplyDeleteThank you very much, because I cannot find suitable ajaxfileupload.js for long time. Good job :)
ReplyDeleteThanks
DeleteHow to get he response in ajax ?. I am using printwriter out ..
ReplyDelete============================
PrintWriter out=response.getWriter();
out.print(resoureFilePath);
====================================
I got the response (object HtmlDcoument) . I need to pass the string in ajax.. Please help me
u got it
DeleteI really appreciate information shared above. It’s of great help. If someone want to learn Online (Virtual) instructor lead live training in AJAX, kindly contact us http://www.maxmunus.com/contact
ReplyDeleteMaxMunus Offer World Class Virtual Instructor led training on AJAX. We have industry expert trainer. We provide Training Material and Software Support. MaxMunus has successfully conducted 100000+ trainings in India, USA, UK, Australlia, Switzerland, Qatar, Saudi Arabia, Bangladesh, Bahrain and UAE etc.
For Demo Contact us.
Nitesh Kumar
MaxMunus
E-mail: nitesh@maxmunus.com
Skype id: nitesh_maxmunus
Ph:(+91) 8553912023
http://www.maxmunus.com/