It looks like you're new here. If you want to get involved, click one of these buttons!
<script type=\"text/javascript\">
$(function(){
$().ready(function(){
$('#file').uploadify({
'uploader': '/Portal3Web/js/external/uploadify.swf',
'script': '/Portal3Web/portal/flash/uploadify',
'cancelImg': '/Portal3Web/images/cancel.png',
'multi': true
});
});
});
</script>
<form method=\"post\" action=\"/Portal3Web/portal/flash/uploadify\" enctype=\"multipart/form-data\" >
<fieldset>
<legend>Upload Files</legend>
<input id=\"file\" name=\"file\" type=\"file\" size=\"50\" />
<br />
<a href=\"javascript:$('#file').uploadifyUpload();\">Upload Files</a>
</fieldset>
</form>
@Controller
@RequestMapping(\"/flash\")
public class FlashAttachmentController {
private Log logger = LogFactory.getLog(this.getClass());
@RequestMapping(value = \"uploadify\", method = RequestMethod.POST)
public ModelAndView handleFlashUpload(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException, FileUploadException {
logger.info(\"FlashAttachmentController ... \");
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
if (! isMultipart) return null;
logger.info(\"Multipart request!\");
// Create a new file upload handler
ServletFileUpload upload = new ServletFileUpload();
// Parse the request
FileItemIterator iter;
try {
//debug
logger.info(\"Getting Iterator...\");
iter = upload.getItemIterator(request);
while (iter.hasNext()) {
FileItemStream item = iter.next();
String name = item.getFieldName();
InputStream inputStream = (InputStream) item.openStream();
if (item.isFormField()) {
String fieldValue = Streams.asString(inputStream);
//debug
logger.info(\"Form field \" + name + \" with value \" + fieldValue + \" detected.\");
inputStream.close();
} else {
//debug
logger.info(\"File field \" + name + \" with file name \" + item.getName() + \" detected.\");
// Process the input stream
File originalFile = FileUtil.getUniqueFile(\"c:/\", StringUtil.getFileName(item.getName()));
try {
uploadToFile(inputStream, originalFile);
} catch (FileNotFoundException ex) {
logger.error(ex);
throw ex;
} catch (IOException ex) {
logger.error(ex);
throw ex;
}
inputStream.close();
logger.info(\"File uploaded successfully!\");
}
}
} catch (Exception ex) {
logger.error(ex);
throw new RuntimeException(ex);
}
return new ModelAndView(\"success\");
}
}
t12ung said:Take your input field out of the form tags, the flash widget handles the post so a form is not needed.
j(\"#srf\").uploadify({
'uploader' : 'scripts/swf/uploadify.swf',
'script' : 'http://127.0.0.1:8080/meritservus/upload/uploadFile.mrk',
'cancelImg' : 'images/cancel.png',
'auto' : true,
'multi' : false,
'scriptAccess' : 'always',
'fileExt' :'*.pdf',
'onAllComplete' : function(event,queueID,fileObj,data){
alert(\"C\");
}
});
alert msg is never showed, but file was uploaded successfully!!!
what is wrong? may be i have return to script some special code or word???
Trollchik said:Thanks, i got success! problem was in Spring security!
Another question, what i have to return to script that "onAllComplete" function will be invoked???
bcs when i have uploaded file, nothing happened!
i have next :
j(\"#srf\").uploadify({
'uploader' : 'scripts/swf/uploadify.swf',
'script' : 'http://127.0.0.1:8080/meritservus/upload/uploadFile.mrk',
'cancelImg' : 'images/cancel.png',
'auto' : true,
'multi' : false,
'scriptAccess' : 'always',
'fileExt' :'*.pdf',
'onAllComplete' : function(event,queueID,fileObj,data){
alert(\"C\");
}
});
alert msg is never showed, but file was uploaded successfully!!!
what is wrong? may be i have return to script some special code or word???