On 02/23/2013 02:37 AM, dmnrmr wrote:
Guys any help? I would really appreciate too see a
simple sample how to
upload and save files to local page?
There are a few missing pieces of information from the documentation, so
it's kind of normal not to be able to get it working on your own, sorry
about that. Here are some hints:
- In XWiki we try to prevent CSRF attacks by requiring that every change
request be accompanied by a token. To make the upload form work, you
must include this in the <form>:
<input type="hidden" name="form_token"
value="$!{services.csrf.getToken()}" />
- The upload action only accepts file inputs named "filepath" (or
filepath_X, where X is a number), so you must change the name of the
file input to "filepath" in order for it to be taken into account
- You MUST keep the JSX object, otherwise the HTML5 upload has no way of
working.
- What you see after the file is uploaded (like in the first screenshot)
is kind of normal, since the HTML5 upload widget doesn't know what you
want to display afterwards. See the "responseURL" parameter. So, this
parameter is almost mandatory if you want something meaningful to
appear. A simple solution is to use the existing attachmentslist.vm
template, which just lists the files uploaded so far to that wiki page,
like in the Attachments tab at the bottom.
Here's some code that works:
{{velocity}}
$xwiki.jsfx.use('uicomponents/widgets/upload.js', true)
$xwiki.ssfx.use('uicomponents/widgets/upload.css', true)
{{html}}
<form action="${doc.getURL('upload')}"
enctype="mutipart/form-data" method="post"><div>
<input type="file" name="filepath" id="my_upload"
/>
<input type="hidden" name="form_token"
value="$!{services.csrf.getToken()}" />
</div></form>
<div id="my_upload_results">
#template('attachmentslist.vm')
</div>
{{/html}}
{{/velocity}}
And the JSX:
document.observe('xwiki:dom:loaded',
function() {
var targetInput = $('my_upload');
if(targetInput) {
new XWiki.FileUploader(targetInput, {
autoUpload: true,
progressAutohide: true,
responseURL: XWiki.currentDocument.getURL('get',
'xpage=attachmentslist'),
responseContainer: $('my_upload_results')
});
}
});
--
Sergiu Dumitriu
http://purl.org/net/sergiu