Example of a Multifile Upload Component swfupload Java environment

Source: Internet
Author: User

This article found that someone sent a short message to ask a question. I want to edit it today.

At the time of posting, there were still few articles about flash file submission on the Internet. Now it's a Google pull. So this article will not update anything ..

In addition, the example is a long time ago. It is not applicable to flash 10 and can only be used in versions earlier than Flash 9, if you want to see the effect, you can return the Flash version of the Local Machine to 9 and check the effect.

==================================================================== ====================

In a web enterprise project just a few weeks ago, you must have the batch upload function, and specify that the file upload function is the same as that of the old system (the old system is a C/S structure, ). There is no way to do it. If you want to do it only through flash, you can find something on the internet, and find this stuff-swfupload.

Official website address is: http://swfupload.mammon.se/

The examples on the official website only include PHP, C #, VB.net, and ror. Then I searched javaeye, as if there were not many, but only one article, which is also relatively advanced, so I can only do it myself.

After that, I thought it was really good and I felt very good at using it. I guess it may be useful for projects in the future.

I made a war package by myself. In a simple example, I passed the test in tomcat5.5 and java5.0 environments.

The package structure is as follows: Java code
 

  1. Index. jsp
  2. Upload. jsp
  3. JS
  4. + ----- Example_callbacks.js
  5. + ----- Swfupload. js
  6. Certificate -----swfupload.swf
Bytes

The above index. jsp is the file upload display page. Upload. jsp is used for the upload function. Two callback functions in JS are used to communicate with SwF, and the other one is the JS file used by itself.

The most important part is the following Java code in index. jsp:
 

  1. VaR swfu;
  2. Window. onload = function (){
  3. Swfu = new swfupload ({
  4. Upload_script: "../upload. jsp", // call the upload function
  5. Target: "swfuploadtarget ",
  6. Flash_path: "JS/swfupload.swf", // location of Flash
  7. Allowed_filesize: 30720, // 30 mb
  8. Allowed_filetypes :"*.*",
  9. Allowed_filetypes_description: "All files ...",
  10. Browse_link_innerhtml: "select ",
  11. Upload_link_innerhtml: "Start upload ",
  12. Browse_link_class: "swfuploadbtn browsebtn ",
  13. Upload_link_class: "swfuploadbtn uploadbtn ",
  14. Flash_loaded_callback: 'swfu. flashloaded ',
  15. Upload_file_queued_callback: "filequeued ",
  16. Upload_file_start_callback: 'uploadfilestart ',
  17. Upload_progress_callback: 'uploadprogress ',
  18. Upload_file_complete_callback: 'uploadfilecomplete ',
  19. Upload_file_cancel_callback: 'uploadfilecanceled ',
  20. Upload_queue_complete_callback: 'uploadqueuecomplete ',
  21. Upload_error_callback: 'uploaderror ',
  22. Upload_cancel_callback: 'uploadcancel ',
  23. Auto_upload: false
  24. })
  25. }
VaR swfu; window. onload = function () {swfu = new swfupload ({upload_script :".. /upload. JSP ", // call the upload function target:" swfuploadtarget ", flash_path:" JS/swfupload.swf ", // allowed_filesize: 30720, // 30 mballowed_filetypes :"*. * ", allowed_filetypes_description:" All files... ", steps:" select ", steps:" Start upload ", browse_link_class:" swfuploadbtn browsebtn ", upload_link_class:" swfuploadbtn uploadbtn ", flash_loaded_callback: 'swfu. flashloaded ', encoding: "filequeued", encoding: 'uploadfilestart', encoding: 'uploadprogress', encoding: 'uploadfilecomplete', encoding: 'uploadfilecanceled', encoding: 'uploadqueuecomplete ', upload_error_callback: 'uploaderror', upload_cancel_callback: 'uploadcancel', auto_upload: false })}

Note that this upload_script attribute is a relative address, which is the path of the SWF file relative to the upload function file. This is easy to make a mistake. In my package, upload. jsp is the upload function. You can see the code and upload a very original file.

In addition, if a 404 error occurs during the upload process, it is generally because the upload_script attribute is set incorrectly. If a 500 error occurs, it is an upload file (upload. jsp) error.

For more information, see the forum on the official website.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.