I am trying to write an API, which takes a .csv file and upload it to s. (I am using node.js lambda) When I upload the CSV file to Postman in form-data and checked the log of body, I got a JSON like this, I can't access the filename or mime type, in (body. file-name/ body.mime/body.file), I need to access these contents,
body:"----------------------------262926577667427333659506\r\nContent-Disposition: form-data; name=\"file\"; filename=\"User_Invoice_Details.csv\"\r\nContent-Type: text/csv\r\n\r\nUser Invoice Details,,,,,,,,,,,,,,,,,,,\r\n,,,,,,,,,,,,,,,,,,,\r\nInvoicenumber,Billingaccountnumber,Username,Invoicedate,Expirydate,Lcoid,Lconame,Customername,Address,Packagename,Cycle,Invoiceamount,Cgst,Sgst,Igst,Totalamount,Statecode,Gstinnumber,Revenueshare,Technology\r\n1734145,INDI0002832755,Treatmentcottage,23-06-2021 12:00,23-07-2021 11:59,LCO002776,S.N.T Network(Patna),Anand Kumar,Mithapur B Area Jakkanpur Behind Bhanamal Work Shop Nahar Par,INDI_UL50,1,483,0,0,0,483,10,,40,EOC\r\nBH2122/06/000001,INDI0001657582,TESA,01-06-2021 12:00,01-07-2021 11:59,LCO002712,Satellite Entertainment(MaripurMuzaffarpur),G.m. Cum Chief Engineer,G.m. Cum CeBhagwanpur Chatti,INDI_UL50,1,483,43.47,0,43.47,569.94,10,,50,Ethernet\r\nBH2122/06/000002,INDI0002300704,vikashkumar@rs,01-06-2021 12:00,01-07-2021 11:59,LCO002775,RS Cable Tv Network(Patna),Vikash Kumar,\"Barah Patthar Ward No 15, Gali No 2,\",INDI_UL50,1,483,43.47,0,43.47,569.94,10,,45,Ethernet\r\nBH2122/06/000003,INDI0002024824,sunny_kumar,01-06-2021 12:00,01-07-2021 11:59,LCO002645,New S K cable(Patna),Sunny Kumar,Neem Gali Sekhpura Patna,INDI_UL50,1,483,43.47,0,43.47,569.94,10,,50,Ethernet\r\nBH2122/06/000004,INDI0001673495,rajhusain_bh,01-06-2021 12:00,01-07-2021 11:59,LCO003066,FLYNET COMMUNICATION (Bhore),Rajhusain Ansari,S/o Hajrat AnsariKarmaini Kateya,EXPRESS,1,483,43.47,0,43.47,569.94,10,,40,Ethernet\r\nBH2122/06/000005,INDI0001850021,yogendra_bh,01-06-2021 12:00,01-07-2021 11:59,LCO003066,FLYNET COMMUNICATION (Bhore),Yogendra Prajapati,S/o Umashankar Prajapati,EXPRESS,1,483,43.47,0,43.47,569.94,10,,40,Ethernet\r\nBH2122/06/000006,INDI0001657842,pmsingh_bh,01-06-2021 12:00,01-07-2021 11:59,LCO003066,FLYNET COMMUNICATION (Bhore),Param Manohar Singh,\"S/o. Ramswaroop Singh , Bairagi Tola, Songarhwa\",EXPRESS,1,483,43.47,0,43.47,569.94,10,,40,Ethernet\r\n,,,,,,,,,,,,,,,,,,,\r\n,,,,,,,,,,,,,,,,,,,\r\n,
CodePudding user response:
You can use lambda-multipart-parser npm package to parse form-data in your lambda function It'll give you the file name and type easily.
const parser = require('lambda-multipart-parser');
const result = await parser.parse(event);
console.log(result.files)