当前位置:网站首页>Project Notes - Take Notes
Project Notes - Take Notes
2022-08-11 06:57:00 【kerodaisuki】
Three elements of file upload
1. Form submission method: POST (there is a size limit for get method submission, post does not)
2. The enctype attribute of the form: must be set to multipart/form-data
Enctype means encodetype means encoding type
Multipart/form-data is a multi-part file upload, which means that the form data is composed of multiple parts, which means both text data and binary data such as files.
3. The form must have a file upload item: file, which must have a name attribute and value
Note: By default, the value of the enctype of the form is application/x-www-form-urlencoded, which cannot be used for file uploading. Only when multipart/form-data is used, the file data can be completely transmitted
Files uploaded by the server
1. Get the content of the request body through request
2. Parse the request body. The feature of multi-component upload is that each input is a form item.
Cut all the content in the request into an array according to the delimiter, each element in the array is a form item
3. Traverse the array and judge which is a normal form and which is a file upload item according to the filename
4. Get the content of the common form item and get it through the attribute name
5. Get the content of the file upload item
File name
File content
6. Use IO to save the file content to the server
FileUpload tool class
1. Import dependencies
The FileUpload package makes it easy to upload files to web applications
IOUtils encapsulates common operations in java and is very convenient to use
2. Introduction to FileUpload core class
DiskFileItemFactory: Disk file item factory, related configuration when reading files, such as: cache size, temporary directory location
ServletFileUpload:A core class for file uploading
FileItem: Represents each form item
3. Detailed explanation of file upload API
ServletFileUpload
isMultipartContent(request); : determine whether it is a file upload form
parseRequest(request); : parse the request to get a collection of form items
setHeaderEncoding("utf-8"): Set the encoding format of the uploaded filename
FileItem
isFormField(): Determine whether it is a normal form item
getFiledName(): Get the name property of the form
item.getString(): Get the value of the form
getName() : Get the name of the uploaded file
getInputStream():Get the uploaded file
delete(): deletes temporary files
4. File upload background code writing
FileUpload steps:
1. Create a disk file item factory
2. Create a core class for file uploading
3. Parse the request - get the file item collection
4. Traverse the file item collection
5. Judging common form items/file upload items
边栏推荐
猜你喜欢
随机推荐
【LeetCode-56】合并区间
无胁科技-TVD每日漏洞情报-2022-7-27
Vulnhub靶机--Chronos
【LeetCode-73】矩阵置零
将UI的点击事件渗透下去
Lua 快速入门(二)——函数(Function)
解决npm warn config global `--global`, `--local` are deprecated. use `--location=global` instead.
SSL证书部署后,为什么还是显示不安全?
中小微企业需要使用SSL证书吗?
C# 基础之字典——Dictionary(二)
C-自定义类型(结构体、枚举、联合)
非对称加密——网络安全
Unity Rebuild和Rebatch浅析
Jmeter RMI 反序列化命令执行漏洞复现
脚本批量打包渠道包研究
无胁科技-TVD每日漏洞情报-2022-7-22
CLR via C# 第五章 基元类型、引用类型和值类型
网络安全学习小结--kali基本工具、webshell、代码审计
Unity 使用双缓冲实现一个好用的计时器
勒索病毒eking.devos.mkp.makop.lockbit.eight.locked.roger等剖析及中毒文件恢复