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"
%>