Multipart data parsing
How do I make an multipart data parsing?
What is a multipart data parsing? How do you make a multipart data parsing? This script and codes were developed by Anthony Pothin on 17 January 2023, Tuesday.
Multipart data parsing - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>multipart data parsing</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css">
</head>
<body> <script src="js/index.js"></script>
</body>
</html>
Multipart data parsing - Script Codes JS Codes
console.clear();
var cType = 'multipart/form-data; boundary=---------------------------285063191120370';
var data = "-----------------------------285063191120370\r\nContent-Disposition: form-data; name=\"username\"\r\n\r\nGroucho\r\n-----------------------------285063191120370\r\nContent-Disposition: form-data; name=\"accountnum\"\r\n\r\n123456\r\n-----------------------------285063191120370\r\n\r\nbalblabla\r\n-----------------------------285063191120370--\r\n";
function parseContentType(contentTypeString) { // supprimer les espaces en début et fin de chaîne contentType = contentTypeString.trim(); var parts = contentType.split(';'); var fullType = parts[0].split('/'); var toReturn = {}; toReturn.mime = parts.shift(); var mime = toReturn.mime.split('/'); toReturn.type = mime[0]; toReturn.subType = mime[1]; if (parts) { toReturn.parameters = {}; for (var i = 0, iMax = parts.length; i < iMax; i++) { var option = parts[i].trim().split('='); toReturn.parameters[option[0]] = option[1]; } } return toReturn;
}
function parseData(contentTypeString, data) { contentTypeObject = parseContentType(contentTypeString); if ( data.substr(0,"\r\n".length) != "\r\n" ) { data = "\r\n"+data; } if (contentTypeObject.type === "multipart") { var parts = extractParts(data, contentTypeObject.parameters.boundary); console.info("parts",parts); // présence d'un content type ??? // si oui, réccursivité switch(contentTypeObject.subType) { case "form-data": break; default: console.error('subtype',contentTypeObject.subType,'for',contentTypeObject.type,'type','not handled'); } /* var parsedData = {}; // extraire chaque sous partie // pour chaque sous partie parser parsedData += parseData(sub_contentType, sub_data);*/ }
}
function extractParts(data, boundary) { var toReturn = []; var partArray = data.split("\r\n"+"--"+boundary); // découper les parties for (var i=0, iMax=partArray.length, parts, part; i<iMax; i++) { // spérare le header du body parts = partArray[i].split("\r\n"+"\r\n", 2); part = { header: parts[0], body: parts[1] }; if (part.body) { toReturn.push(part); } } return toReturn;
}
document.body.textContent = parseData(cType, data);
Developer | Anthony Pothin |
Username | Thorien |
Uploaded | January 17, 2023 |
Rating | 3 |
Size | 2,260 Kb |
Views | 4,048 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Form - form | 3,487 Kb |
Form - checkbox | 3,829 Kb |
Custom list picker | 5,009 Kb |
Tab bar | 3,423 Kb |
Flexible accordion | 2,356 Kb |
Magic table | 8,674 Kb |
A Pen by Anthony Pothin | 4,034 Kb |
Responsive slide | 2,400 Kb |
Demo component | 2,725 Kb |
Custom scrollbar | 7,800 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Simple blog concept | Drew_mc | 2,666 Kb |
Direction-icon | Alexandremasy | 3,323 Kb |
Simple star rating using js and data-uri | TheEnd | 5,795 Kb |
Planet Awesome | Bartuc | 3,554 Kb |
CSSOff 2013 Submission | Codewunder | 14,766 Kb |
Process Accordion | Devilskitchen | 31,432 Kb |
Pure CSS Tooltips | Mobius1 | 2,271 Kb |
Layout 11 | Altynai | 1,690 Kb |
Tree growth tests | Orchard | 3,818 Kb |
Loading animation - freedom purchase | Rocbear | 2,567 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!