檔案上傳功能Demo

2021-10-07 11:45:42 字數 2103 閱讀 2483

檔案上傳功能demo

控制層**

(

"/upload"

)public returnvalue uploadfiletest

(@requestparam

("uploadfile"

) multipartfile zipfile)

/* multipartfile 類

*/

服務層**

returnvalue uploadfiletest

(multipartfile zipfile)

;

服務實現層**

@service

public

class

subfundvaluationserviceimpl

implements

subfundvaluationservice

// uuid 通用唯一識別碼是由一組32位數的16進製制數字所構成,是故 uuid 理論上的總數為1632=2128,約等於3.4 x 10123。也就是說若每納秒產生1百萬個 uuid,要花100億年才會將所有 uuid 用完

// string filename = uuid.randomuuid().tostring().replace("-", "");

// string filesuffix = getfilesuffix(zipfile);

// if (filesuffix != null)

file targetfile =

newfile

(targetfilepath + file.separator + filename)

; fileoutputstream fileoutputstream = null;

trycatch

(ioexception e)

finally

catch

(ioexception e)

}return

newreturnvalue

<

>

(returncodeandmsgenum.success, null);}

// 獲取檔案字尾名()

private string getfilesuffix

(multipartfile file)

string filename = file.

getoriginalfilename()

;int suffixindex = filename.

lastindexof

(".");

if(suffixindex ==-1

)else

}}

測試介面

資料夾生成結果

uuid生成的唯一識別碼由數字和字母組成,通過入參可以直接拿到檔名

附加:配置檔案

spring

:servlet

:multipart

:max-file-size

: 50mb

max-request-size

: 50mb mb必須大寫(有坑)

#單個檔案最大限制:

spring.servlet.multipart.max-file-size=50mb

#單次請求最大限制:

spring.servlet.multipart.max-request-size=70mb

# 字母大小寫未檢測

python檔案上傳功能

客戶端檔案上傳功能 import os import socket 建立客戶端socket物件 client socket socket.socket ip 和 port address ip,port 客戶端連線 client socket.connect address 檔案路徑 base di...

php 檔案上傳功能

php 檔案上傳功能 點選瀏覽,將所選的檔案上傳到建立的images資料夾內 如下 無標題文件 title head body h1 上傳檔案 h1 form action chuli.php method post enctype multipart form data 請選擇檔案 input t...

PHP的檔案上傳功能

下面介紹一下使用php上傳檔案的一段 if empty files up picture name elseelse path upfile time strtolower strstr files up picture name 定義上傳檔名稱和儲存位置 if is uploaded file f...