GithubHelp home page GithubHelp logo

ajaxfileupload.js's Introduction

Ajaxfileupload.js

jquery ajax 文件上传的插件,验证可用。

前端用例


function imageUpload(){
        alert("hello");
        $.ajaxFileUpload({
            url : '/BusinessTrip/upload', //用于文件上传的服务器端请求地址
            fileElementId : 'image_face', //文件上传空间的id属性  <input type="file" id="file" name="file" />
            type : 'post',
            dataType : 'text', //返回值类型 一般设置为json
            success : function(data, status) //服务器成功响应处理函数
            {
                alert("头像上传成功");
                //$("#picList").datagrid('reload');
                //$('#uploadPicWindow').window('close');
                // alert(data.msg);
            },
            error : function(data, status, e)//服务器响应失败处理函数
            {
                alert("图片上传失败");
                //$("#picList").datagrid('reload');
                //$('#uploadPicWindow').window('close');
                // alert(data.msg);
            }
        });
    }
   

服务器端用例


        @Controller
        public class UploadController {

            @Resource
            public UserClientService userService;

            @RequestMapping(value = "upload", method = RequestMethod.POST)
            public @ResponseBody
            String upload(HttpServletRequest request,
                          HttpServletResponse response, ModelMap model,HttpSession session) throws IOException {
                MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
                MultipartFile mFile = multipartRequest.getFile("file");
                String path = request.getSession().getServletContext().getRealPath("/resources/upload");
                String filename = mFile.getOriginalFilename();
                InputStream inputStream = mFile.getInputStream();
                byte[] b = new byte[1048576];
                int length = inputStream.read(b);
                Date date = new Date();
                SimpleDateFormat F = new SimpleDateFormat("yyyyMMddHHmmss");
                String prefix=filename.substring(filename.lastIndexOf("."));
                filename = "123" + F.format(date) + prefix;
                String url =path +"/"+ filename;
                System.out.println(url);
                FileOutputStream outputStream = new FileOutputStream(url);
                outputStream.write(b, 0, length);
                inputStream.close();
                outputStream.close();
                return "success";
            }
        }

ajaxfileupload.js's People

Contributors

jaxonhu avatar

Watchers

James Cloos avatar qingkong avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.