Multi-image Batch Upload

Source: Internet
Author: User

0. Preface


Online most pictures batch upload code old incomplete, then into a sub-text, in order to save Bo friends time



I. Code examples


Front-end code (use HTML5 Multiple property to support multi-image bulk uploads):

<form action= "" Enctype= ' Multipart/form-data ' method= "post" >    <div class= "Form-item" >        <label > Upload Images </label>        <input type= "file" value= "select Picture" Name= "image[]" multiple>    </div></ Form>



Backend processing code://access to the foreground of the picture resources (here with the GetFiles () method is roughly expressed, because this is related to the Controller framework, such as SPRINGMVC, struts and so on, may even be the Servlet direct access, specific project use, This is not an example.)
fileitem[] files = GetFiles ("image[]");            list<string> pictureurllist = new arraylist<string> (); for (int index = 0; index < files.length; index++) {try {byte[] bytes = Ioutils.tob                    Ytearray (Files[index].getinputstream ());                    String filename = Files[index].getfilename (); Picture upload path, may be stand-alone picture server, may also be put together with the application String Uploadpath = "http://img.cdn.com/upload/image/"; String extension = filenameutils.getextension (filename). toLowerCase ();                    Customize a function that generates a non-repeating file name GetFileName () String filename = getfilename () + extension;                    Upload file Pathtosave = new file (uploadpath, filename);                    if (!pathtosave.getparentfile (). exists ()) {Pathtosave.getparentfile (). Mkdirs ();           } fileoutputstream fos = new FileOutputStream (pathtosave);         Ioutils.write (bytes, FOS); } catch (Exception e) {}}



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Multi-image Batch Upload

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.