[xwiki-users] Cannot use FileUploadPlugin !?
Hi, I want to create a page allowed to upload more files together using FileUploadPlugin. I created 2 documents but the FileUploadPlugin seems not work, the data return is null and the document MySpace.Upload is attached with a file 0KB. Anyone can explain me why this happens ? And how to fix ? 1. MySpace.doc: <form action="/xwiki/bin/view/MySpace/Upload" enctype="multipart/form-data" method="post"> <input type="file" name="filepath" value="" size="40" /> <input type="submit" value="Save" /> </form> 2. MySpace.Upload <% import com.xpn.xwiki.plugin.fileupload.FileUploadPlugin; import com.xpn.xwiki.doc.XWikiDocument; import com.xpn.xwiki.doc.XWikiAttachment; print "Start upload... "; def docu=doc.getDocument(); FileUploadPlugin fileupload = (FileUploadPlugin) context.getContext().get("fileuploadplugin"); byte[] data = fileupload.getFileItemData("filepath", context.getContext()); def filename = "myfile"; def attachment = docu.getAttachment(filename); print data; if (!attachment) { attachment = new XWikiAttachment(docu, filename); docu.getAttachmentList().add(attachment); } attachment.setContent(data); docu.saveAttachmentContent(attachment, context.getContext()); doc.save() println "done" %>
Which version of XWiki are you using ? There is some issue that makes some code empty the file upload list. Can you try by posting to a page with that in the URL ?xpage=plain Also you should be able to do this without going to the internal API. There is addAttachment in Document Here is a test code that shows the file upload plugin in action to show that you get data: 1 File Upload Snipplet <% if (request.get("submitter")!=null) { def fupl= xwiki.get("fileupload"); println fupl; def myfiles = fupl.getFileItems(); println "{pre}" println myfiles; println "{/pre}" println fupl.getFileName("file") } else { %> <form action="" enctype="multipart/form-data" method="post"> <table border="0"> <tr> <td>Submitter:</td><td><input type="text" name="submitter" /></td> </tr><tr> <td>File:</td><td><input type="file" name="file" /></td> </tr><tr> <td colspan="2" align="center"> <input type="submit" /> </td> </tr> </table> </form> <% } %> Ngo Thi Hong Nga wrote:
Hi, I want to create a page allowed to upload more files together using FileUploadPlugin. I created 2 documents but the FileUploadPlugin seems not work, the data return is null and the document MySpace.Upload is attached with a file 0KB. Anyone can explain me why this happens ? And how to fix ?
1. MySpace.doc: <form action="/xwiki/bin/view/MySpace/Upload" enctype="multipart/form-data" method="post"> <input type="file" name="filepath" value="" size="40" /> <input type="submit" value="Save" /> </form> 2. MySpace.Upload <% import com.xpn.xwiki.plugin.fileupload.FileUploadPlugin; import com.xpn.xwiki.doc.XWikiDocument; import com.xpn.xwiki.doc.XWikiAttachment;
print "Start upload... "; def docu=doc.getDocument(); FileUploadPlugin fileupload = (FileUploadPlugin) context.getContext().get("fileuploadplugin"); byte[] data = fileupload.getFileItemData("filepath", context.getContext()); def filename = "myfile"; def attachment = docu.getAttachment(filename);
print data; if (!attachment) { attachment = new XWikiAttachment(docu, filename); docu.getAttachmentList().add(attachment); } attachment.setContent(data); docu.saveAttachmentContent(attachment, context.getContext()); doc.save()
println "done" %> _______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
-- Ludovic Dubost Blog: http://blog.ludovic.org/ XWiki: http://www.xwiki.com Skype: ldubost GTalk: ldubost
I use XE 1.1.2. I create a document and paste your test code in. After browse a file, click Submit, the following line is displayed: com.xpn.xwiki.plugin.fileupload.FileUploadPluginApi@1015495 null null
Can you try by changing <form action=""> to <form action="$doc.getURL("view" , "xpage=plain")"> Ludovic Ngo Thi Hong Nga wrote:
I use XE 1.1.2. I create a document and paste your test code in. After browse a file, click Submit, the following line is displayed:
com.xpn.xwiki.plugin.fileupload.FileUploadPluginApi@1015495 null null ------------------------------------------------------------------------
_______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
-- Ludovic Dubost Blog: http://blog.ludovic.org/ XWiki: http://www.xwiki.com Skype: ldubost GTalk: ldubost
Still the same result: null :( Have you tested your code snippet before posted here? Does it run properly? If yes, which version of XE you are using ? Can you test my code in your XE and tell me the result ?
It runs fine on 1.2 and 1.3 Try an upgrade Ludovic Ngo Thi Hong Nga wrote:
Still the same result: null :( Have you tested your code snippet before posted here? Does it run properly? If yes, which version of XE you are using ? Can you test my code in your XE and tell me the result ? ------------------------------------------------------------------------
_______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
-- Ludovic Dubost Blog: http://blog.ludovic.org/ XWiki: http://www.xwiki.com Skype: ldubost GTalk: ldubost
participants (2)
-
Ludovic Dubost -
Ngo Thi Hong Nga