开发者

need an example of using SWFUpload with java

开发者 https://www.devze.com 2023-01-01 10:40 出处:网络
i am new to SWFUpl开发者_如何学Gooad , and i am reading the documentation now, and i need an example using SWFUpload with java please, thank you.Example implementation for SWFUpload, jQuery, JSP, Java

i am new to SWFUpl开发者_如何学Gooad , and i am reading the documentation now, and i need an example using SWFUpload with java please, thank you.


Example implementation for SWFUpload, jQuery, JSP, Java and Spring

First the jsp:

<%@ page language="java" pageEncoding="UTF-8" %>
<head>
<script type="text/javascript" src="<c:url value="/public/js/swfupload/swfupload.js"/>"></script>  
<script type="text/javascript" src="<c:url value="/public/js/jquery-plugins/ jquery.swfupload.js"/>"></script> 
<script type="text/javascript">
$(function(){
    $('.swfupload-control').swfupload({
        // Backend Settings
        upload_url: "<c:url value="/upload;jsessionid=${pageContext.session.id}"/>",    // Relative to the SWF file (or you can use absolute paths)

        // Flash Settings
        flash_url : "<c:url value="/public/js/swfupload/swfupload.swf"/>",

    //IMPORTANT: you need to set file_post_name otherwise flash sets it as Filedata, which does not conform to bean naming conventions. 
        file_post_name: "file",

        // File Upload Settings
        file_size_limit : "102400", // 100MB
        file_types : "*.*",
        file_types_description : "All Files",
        file_upload_limit : "10",
        file_queue_limit : "0",

        // Button Settings
        button_image_url : "<c:url value="/public/js/swfupload/XPButtonUploadText_61x22.png"/>", // Relative to the SWF file
        button_placeholder_id : "spanButtonPlaceholder",
        button_width: 61,
        button_height: 22



    });


    // assign our event handlers
    $('.swfupload-control')
        .bind('fileQueued', function(event, file){
            // start the upload once a file is queued
            $(this).swfupload('startUpload');
        })
        .bind('uploadComplete', function(event, file){
            alert('Upload completed - '+file.name+'!');
            // start the upload (if more queued) once an upload is complete
            $(this).swfupload('startUpload');
        });

}); 

</script>
<head>
<body>
<div id="file_upload"></div>
<div class="swfupload-control">
   <span id="spanButtonPlaceholder"></span>
</div>
</body>

Controller:

@Controller
public class UploadController {
Logger logger = LoggerFactory.getLogger(this.getClass());

@RequestMapping(value="/upload", method=RequestMethod.POST)
public String addMultiple(
    final HttpServletRequest request
    , final HttpServletResponse response
    , @RequestParam("file") MultipartFile file //NOTE: `@RequestParam("file")` matches `file_post_name: "file"`
    ){
        logger.debug(uploadedFile.getOriginalFilename());

    }
} 

Also, make sure you've got this in your configs:

<bean id="multipartResolver"
   class="org.springframework.web.multipart.commons.CommonsMultipartResolver">

</bean>

If you are not using spring you might be able to cast the HttpServeletRequest as a MultiPartRequestWrapper use:

File[] files = ((MultiPartRequestWrapper)request).getFiles("Filedata");

This solution doesn't require COS (Com O'Reilly Servlet). Instead it just uses the more common javax.servlet.http.HttpServletRequest

Sources (stackoverflow wouldnt let me post links):

  1. swfupload.org/forum/generaldiscussion/1087
  2. demo.swfupload.org/Documentation/#setFilePostName
  3. blogs.bigfish.tv/adam/2009/06/14/swfupload-jquery-plugin/
  4. webdeveloperplus.com/jquery/multiple-file-upload-with-progress-bar-using-jquery/ (prettier implemenation of jquery uploader)


http://e-blog-java.blogspot.com/2011/03/upload-using-swfupload-component.html

He had also given a sample source code to see it in action.

0

精彩评论

暂无评论...
验证码 换一张
取 消