webuploader + springmvc上傳

首先去官網下載:http://fex.baidu.com/webuploader/download.html php

前臺: html

放到項目裏面,修改upload.js中的server:'up'; web

修改webuploader.js中的sendAsBinary: false spring


  • sendAsBinary {Object} [可選] [默認值:false] 

    是否已二進制的流的方式發送文件,這樣整個上傳內容php://input都爲文件內容, 其餘參數在$_GET數組中。 數組

能夠修改一下提示和上傳文件的類型以及大小: mvc

 uploader.onError = function( code ) {
            
        if(code=="Q_EXCEED_NUM_LIMIT"){
    alert("超出最大張數!");
    }else if(code=="F_DUPLICATE"){
    alert("文件重複!");
    }else if(code=="Q_TYPE_DENIED"){
    alert("不容許上傳的類型!");
    }else{
    alert( 'Eroor: ' + code );
    }
        }; app

後臺: spa

修改springmvc的配置文件  code

<beans:bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
</beans:bean> server

Controller中:

@RequestMapping(value = ("/up"), method = RequestMethod.POST)
public void upload(@RequestParam("file") MultipartFile file,HttpServletRequest request,HttpServletResponse response) {
try {

//獲得圖片去保存吧! UpfileInfo up = super.upload(file, request,tid); upfileService.add(up); } catch (Exception e) { e.printStackTrace(); } }

相關文章
相關標籤/搜索