文件上传后无法访问正文中的参数
can't access parameters in body after file upload
我正在尝试编写一个 API,它需要一个 .csv 文件并将其上传到 s。 (我正在使用 node.js lambda)
当我在表单数据中将 CSV 文件上传到 Postman 并检查 body 的日志时,我得到了这样的 JSON,我无法访问文件名或 mime 类型,在 (body.file-name/ body .mime/body.file), 我需要访问这些内容,
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,
您可以使用 lambda-multipart-parser npm 包在您的 lambda 函数中解析表单数据它会很容易地为您提供文件名和类型。
const parser = require('lambda-multipart-parser');
const result = await parser.parse(event);
console.log(result.files)
我正在尝试编写一个 API,它需要一个 .csv 文件并将其上传到 s。 (我正在使用 node.js lambda) 当我在表单数据中将 CSV 文件上传到 Postman 并检查 body 的日志时,我得到了这样的 JSON,我无法访问文件名或 mime 类型,在 (body.file-name/ body .mime/body.file), 我需要访问这些内容,
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,
您可以使用 lambda-multipart-parser npm 包在您的 lambda 函数中解析表单数据它会很容易地为您提供文件名和类型。
const parser = require('lambda-multipart-parser');
const result = await parser.parse(event);
console.log(result.files)