当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
处理eking.Devos勒索病毒防范解密恢复操作攻略
C-动态内存管理
IO流和序列化与反序列化
C语言-7月21日-指针的深入
胖鸟博客之勒索病毒紧急处理文件恢复及防范方案
无胁科技-TVD每日漏洞情报-2022-8-1
Apache Fink 文件上传漏洞复现及利用
【LeetCode-350】两个数组的交集II
GoAhead Server 环境变量注入(CVE-2021-42342)漏洞复现
无胁科技-TVD每日漏洞情报-2022-7-21
MySQL中忘记用户密码怎么办?
【LeetCode-74】搜索二维矩阵
web网络安全笔记
欧拉角、四元数与旋转
中小微企业需要使用SSL证书吗?
无胁科技-TVD每日漏洞情报-2022-7-27
IndexError: index 9 is out of bounds for axis 0 with size 9;数组下标溢出问题
无胁科技-TVD每日漏洞情报-2022-7-20
Vulnhub靶机--born2root
Unity3D中所有特殊的文件夹