版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
文件上傳功能目錄21.技術(shù)原理2.效果圖預(yù)覽3.實現(xiàn)步驟4.功能驗證測試技術(shù)原理3(1)視圖層:彈出文件上傳的操作界面(2)控制層:接收視圖層的消息,向服務(wù)層發(fā)送文件上傳參數(shù),并將服務(wù)層返回的結(jié)果發(fā)送到視圖層(3)服務(wù)層:調(diào)用swift提供的接口實現(xiàn)文件上傳,并將上傳結(jié)果返回給控制層功能描述4實現(xiàn)步驟5在cn/edu/sict/cloud/storage/service/SwiftStorageService.java添加如下代碼public
booleancreateFile(Stringusername,Stringpath,Stringname,Stringfilepath){SwiftDFSswiftdfs=newSwiftDFS();swiftdfs.createFile(username,path,name,filepath);return
true;}實現(xiàn)步驟6在cn/edu/sict/cloud/storage/sh/SwiftDFS.java添加如下代碼public
booleancreateFile(Stringrootpath,Stringpath,Stringname,Stringfilepath){if(path.equals("")){path=null;}else{path=path.substring(0,path.length()-1);}os.objectStorage().objects().put(rootpath,name,Payloads.create(newFile(filepath)),ObjectPutOptions.create().path(path));return
true;}實現(xiàn)步驟7在cn/edu/sict/cloud/storage/Web/StorageController.java添加如下代碼@RequestMapping("/uploadfile")@ResponseBodypublicObjectuploadfile(HttpServletRequestrequest,HttpServletResponseresponse,@RequestParam(value="qqfile",required=true)MultipartFilefile){try{if(!file.isEmpty()){byte[]bytes=file.getBytes();Stringupath=request.getSession().getServletContext().getRealPath("/");Stringuuid=UUID.randomUUID().toString();Stringpath="upload/"+uuid+file.getOriginalFilename();FileOutputStreamfos=newFileOutputStream(upath+path);fos.write(bytes);實現(xiàn)步驟8在cn/edu/sict/cloud/storage/Web/StorageController.java添加如下代碼fos.close();return
newMessageBean(true,Constants.SUCCESS_4,path);}else{return
newMessageBean(false,Constants.ERROR_6);}}catch(Exceptione){return
newMessageBean(false,Constants.ERROR_6);}}實現(xiàn)步驟9在cn/edu/sict/cloud/storage/Web/StorageController.java添加如下代碼@RequestMapping("/createfile")@ResponseBodypublicObjectcreatefile(HttpServletRequestrequest,HttpServletResponseresponse,Stringpath,Stringname,Stringfilepath){Useruser=getSessionUser(request);Stringupath=request.getSession().getServletContext().getRealPath("/");boolean
flag=false;flag=storage.createFile(user.getUsername(),path,name,upath+filepath);return
newMessageBean(flag,flag?Constants.SUCCESS_4:Constants.ERROR_5);}實現(xiàn)步驟10采用“fineuploader”控件實現(xiàn)文件上傳,特點:(1)支持文件上傳顯示;(2)文件拖拽瀏覽器上傳方式;(3)Ajax頁面無刷新;(4)多文件上傳;(5)跨瀏覽器;(6)跨后臺服務(wù)端語言使用該控件需要引用js文件:<scriptsrc="assets/javascripts/fineuploader.js"></script>實現(xiàn)步驟11在main.jsp文件的js中添加如下代碼實現(xiàn)文件上傳functioncreateUploader(){varuploader=newqq.FineUploader({element:document.getElementById('result-uploader'),request:{endpoint:'uploadfile.action'},text:{uploadButton:'<iclass="glyphiconglyphicon-plus"></i>上傳文件'},實現(xiàn)步驟12在main.jsp文件的js中添加如下代碼實現(xiàn)文件上傳template:'<divclass="qq-uploader">'+'<preclass="qq-upload-drop-area"><span>{dragZoneText}</span></pre>'+'<divclass="qq-upload-buttonbtnbtn-defaultbtn-sm"style="background:#F6F6F6;border:1pxsolidrgb(206,206,206);display:inline;top:3px;padding:5px15px7px15px;width:100%;position:relative;overflow:hidden;border-radius:0;">{uploadButtonText}</div>'+'<spanclass="qq-drop-processing"style="display:none"><span>{dropProcessingText}</span>'+'<spanclass="qq-drop-processing-spinner"></span></span>'+'<ulclass="qq-upload-list"style="margin-top:10px;text-align:center;display:none"></ul>'+'</div>',實現(xiàn)步驟13在main.jsp文件的js中添加如下代碼實現(xiàn)文件上傳classes:{success:'alertalert-success',fail:'alertalert-error'},callbacks:{onComplete:function(id,fileName,responseJSON){if(responseJSON.success){varfielpath=responseJSON.other;createfile(fileName,fielpath);}}}});}實現(xiàn)步驟14在main.jsp文件的js中添加如下代碼實現(xiàn)文件上傳functioncreatefile(fileName,filepath){va
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 公司搞笑口號簡短霸氣
- 2024年生活垃圾焚燒發(fā)電項目建議書
- 專題2 兩、三位數(shù)除以一位數(shù)(數(shù)與代數(shù))-2023-2024學(xué)年三年級上冊數(shù)學(xué)寒假專項提升(蘇教版)
- 專題1 乘法-2023-2024學(xué)年四年級上冊數(shù)學(xué)計算大通關(guān)(北師大版)
- 2024年度江西省安全員之B證(項目負責(zé)人)通關(guān)提分題庫(考點梳理)
- 2024年度江西省安全員之A證(企業(yè)負責(zé)人)能力檢測試卷B卷附答案
- 你最喜歡的農(nóng)作物有哪些
- 巴揚管科目模擬考試題
- 2024年數(shù)控弧齒錐齒輪銑齒機項目合作計劃書
- 2024年護理服務(wù)項目發(fā)展計劃
- 政府投資項目審計
- 分布式光伏電站發(fā)電量損失補償保險條款(2022版)
- 汽車后備箱創(chuàng)意市集活動策劃方案(樂創(chuàng)集市 潮玩車尾主題)
- 民法典-婚姻家庭編課件
- 中藥濕敷技術(shù)
- 山東足球場人造草工程施工合同
- 腫瘤患者精細化營養(yǎng)管理理論考試試題及答案
- (新)海陸分布與氣候課件
- 推拿治療學(xué)-課件
- 學(xué)校食堂食品安全信用檔案模版
- 螺紋牙強度校核計算
評論
0/150
提交評論