我正在尝试编写一个API,它需要一个。csv文件并将其上传到s.(我使用node.js lambda)当我在form-data中上传CSV文件到Postman并检查body的日志时,我得到了一个这样的JSON,我无法访问(body中的)文件名或mime类型。file-name/body.mime/body.file),我需要访问这些内容,
body:"----------------------------262926577667427333659506rnContent-Disposition: form-data; name="file"; filename="User_Invoice_Details.csv"rnContent-Type: text/csvrnrnUser Invoice Details,,,,,,,,,,,,,,,,,,,rn,,,,,,,,,,,,,,,,,,,rnInvoicenumber,Billingaccountnumber,Username,Invoicedate,Expirydate,Lcoid,Lconame,Customername,Address,Packagename,Cycle,Invoiceamount,Cgst,Sgst,Igst,Totalamount,Statecode,Gstinnumber,Revenueshare,Technologyrn1734145,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,EOCrnBH2122/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,EthernetrnBH2122/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,EthernetrnBH2122/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,EthernetrnBH2122/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,EthernetrnBH2122/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,EthernetrnBH2122/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,Ethernetrn,,,,,,,,,,,,,,,,,,,rn,,,,,,,,,,,,,,,,,,,rn,
你可以使用lambda-multipart-parser npm包来解析lambda函数中的表单数据,它会很容易地给你文件名和类型。
const parser = require('lambda-multipart-parser');
const result = await parser.parse(event);
console.log(result.files)