Python Forum
parsing mutipart form data in Lambda
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
parsing mutipart form data in Lambda
#4
Depends on what you want,quick and dirty way to get contend with regex.
import re

data = '''\
----------------------------124218046032878137249340
Content-Disposition: form-data; name="file1"; filename="2.csv"

Content-Type: text/csv

header,value

a,1
b,2

----------------------------124218046032878137249340

Content-Disposition: form-data; name="file2"; filename="1.txt"

Content-Type: text/plain

aa
bb
cc'''

r_csv = re.search(r'Content-Type: text/csv(.*\,\w)', data, re.DOTALL)
lst = [i for i in r_csv.group(1).split('\n') if i != '']
result = [i.split(',') for i in lst]
print(result)
print('--------------------------')
r_text = re.search(r'Content-Type: text/plain(.*)', data, re.DOTALL)
print([i for i in r_text.group(1).split('\n') if i != ''])
Output:
[['header', 'value'], ['a', '1'], ['b', '2']] -------------------------- ['aa', 'bb', 'cc']
Reply


Messages In This Thread
parsing mutipart form data in Lambda - by v71017 - Mar-08-2018, 10:32 AM
RE: parsing mutipart form data in Lambda - by snippsat - Mar-08-2018, 01:17 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Sending data from the form to DB quisatz 5 1,473 Sep-27-2023, 04:58 PM
Last Post: quisatz
Video doing data treatment on a file import-parsing a variable EmBeck87 15 3,089 Apr-17-2023, 06:54 PM
Last Post: EmBeck87
  Unable to request image from FORM Data usman 0 1,036 Aug-18-2022, 06:23 PM
Last Post: usman
  json api data parsing elvis 0 964 Apr-21-2022, 11:59 PM
Last Post: elvis
  Modify values in XML file by data from text file (without parsing) Paqqno 2 1,793 Apr-13-2022, 06:02 AM
Last Post: Paqqno
  I need help parsing through data and creating a database using beautiful soup username369 1 1,754 Sep-22-2021, 08:45 PM
Last Post: Larz60+
  Problem: Retrieving Form data PythonDev 3 3,174 Oct-16-2020, 02:09 AM
Last Post: PythonDev
  Write lambda function in pyhhon to coy data from multiple JSON into a single JSON fil anandmn85 2 4,307 Apr-19-2018, 05:56 AM
Last Post: anandmn85
  how to parse multipart/form-data for xls or jpeg stream into python code and store v71017 0 3,386 Mar-20-2018, 01:09 PM
Last Post: v71017
  Parsing serial data "Attribute Error" Zeberoff 2 3,487 Jan-04-2018, 09:57 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020