Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Upoadify with spring implementation help
  • I am trying get uploadify to work with java spring framework. The problem I am currently facing is, upoadify never makes a HTTP POST request. If I include the 'checkscript' option (just to check) with the same url as 'script', I see that an ajax request is made and the controller successfully prints out a log message.

    Please take a look at the following code. Any help is much appreciated. Thanks !


    ********************script and uploadify elements from jsp**************************


    $(function(){
    $().ready(function(){
    $('#file').uploadify({
    'uploader': '/Portal3Web/js/external/uploadify.swf',
    'script': '/Portal3Web/portal/flash/uploadify',
    'cancelImg': '/Portal3Web/images/cancel.png',
    'multi': true
    });
    });
    });




    Upload Files



    Upload Files




    *****************************Controller **********************************

    @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");
    }
    }
  • I am trying get uploadify to work with java spring framework. The problem I am currently facing is, upoadify never makes a HTTP POST request. If I include the 'checkscript' option (just to check) with the same url as 'script', I see that an ajax request is made and the controller successfully prints out a log message.

    Please take a look at the following code. Any help is much appreciated. Thanks !


    ********************script and uploadify elements from jsp**************************


    <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 **********************************


    @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\");
    }
    }
  • Take your input field out of the form tags, the flash widget handles the post so a form is not needed.
  • t12ung said:
    Take your input field out of the form tags, the flash widget handles the post so a form is not needed.


    Did that ... but anyways this should not be the problem.

    In my case uploadify flash object is not able to communicate with my controller. 'checkscript' makes an ajax request and comes from the same session, so it communicates with the controller without problems. I think it has something to do with the session.
  • I have the same problem with Spring! no communication between script and controller! PLEASE HELP!
  • Did you try setting 'method' - 'POST' though default is set to POST anyway.
  • 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???
  • 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???


    Hey Trollchik,

    Can you please describe what exactly did you do to solve the communication issue between the flash and the controller ?

    Thanks !