File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11# formdata-parser
22Parse the form data
3+
4+
5+ ## Installation
6+
7+ ` npm install @trojs/formdata-parse `
8+ or
9+ ` yarn add @trojs/formdata-parse `
10+
11+ ## Test the package
12+
13+ ` npm run test `
14+ or
15+ ` yarn test `
16+
17+ ## How to use
18+
19+
20+ ``` javascript
21+ import parseFormData from ' @trojs/formdata-parse' ;
22+
23+ const response = parseFormData (' -----------------------------12946965154256166883262710838\r\n ' +
24+ ' Content-Disposition: form-data; name="fileName"; filename="test.txt"\r\n ' +
25+ ' Content-Type: text/plain\r\n ' +
26+ ' \r\n ' +
27+ ' 42\n ' +
28+ ' \r\n ' +
29+ ' -----------------------------12946965154256166883262710838\r\n ' +
30+ ' Content-Disposition: form-data; name="fileName2"; filename="test.xml"\r\n ' +
31+ ' Content-Type: text/xml\r\n ' +
32+ ' \r\n ' +
33+ ' 43\n ' +
34+ ' \r\n ' +
35+ ' -----------------------------12946965154256166883262710838--\r\n ' , ' multipart/form-data; boundary=---------------------------12946965154256166883262710838' )
36+ ```
37+
38+ Result:
39+ ``` javascript
40+ [
41+ {
42+ fieldName: ' fileName' ,
43+ fileName: ' test.txt' ,
44+ contentType: ' text/plain' ,
45+ fileData: ' 42\n ' ,
46+ boundary: ' ---------------------------12946965154256166883262710838'
47+ },
48+ {
49+ fieldName: ' fileName2' ,
50+ fileName: ' test.xml' ,
51+ contentType: ' text/xml' ,
52+ fileData: ' 43\n ' ,
53+ boundary: ' ---------------------------12946965154256166883262710838'
54+ }
55+ ]
56+ ```
57+
58+ Types:
59+ ``` typescript
60+ {
61+ fileName : string ;
62+ fileData : string ;
63+ field : string ;
64+ contentType : string ;
65+ boundary : string ;
66+ }
67+ ```
68+ See also the form-data.d.ts file
You can’t perform that action at this time.
0 commit comments