Skip to content

trojs/formdata-parser

Repository files navigation

formdata-parser

Parse the form data

Installation

npm install @trojs/formdata-parse or yarn add @trojs/formdata-parse

Test the package

npm run test or yarn test

How to use

import parseFormData from '@trojs/formdata-parse';

 const response = parseFormData('-----------------------------12946965154256166883262710838\r\n' +
    'Content-Disposition: form-data; name="fileName"; filename="test.txt"\r\n' +
    'Content-Type: text/plain\r\n' +
    '\r\n' +
    '42\n' +
    '\r\n' +
    '-----------------------------12946965154256166883262710838\r\n' +
    'Content-Disposition: form-data; name="fileName2"; filename="test.xml"\r\n' +
    'Content-Type: text/xml\r\n' +
    '\r\n' +
    '43\n' +
    '\r\n' +
    '-----------------------------12946965154256166883262710838--\r\n', 'multipart/form-data; boundary=---------------------------12946965154256166883262710838')

Result:

[
  {
    fieldName: 'fileName',
    fileName: 'test.txt',
    contentType: 'text/plain',
    fileData: '42\n',
    boundary: '---------------------------12946965154256166883262710838'
  },
  {
    fieldName: 'fileName2',
    fileName: 'test.xml',
    contentType: 'text/xml',
    fileData: '43\n',
    boundary: '---------------------------12946965154256166883262710838'
  }
]

Types:

{
    fileName: string;
    fileData: string;
    field: string;
    contentType: string;
    boundary: string;
}

See also the src/types.d.ts file

About

Parse the form data

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Sponsor this project

  •  

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy