在嵌套数组中上传多个特定用户的多个图像时遇到问题

enderforlicesedetails是一个嵌套数组名称,每个对象都包含带有文件详细信息的许可图,我不可能像multer中提到的那样以formdata发送二进制。

this is how i am sending from frontend  this only receive ProfileImage and TRainerPermitImage 
const InstructorFormData = new FormData();
    let InstructorDataNoImage = {};
for (let [key, value] of Object.entries(InstructorData)) {
    console.log("key:", key, "value:", value);
    if (key.indexOf("Image") > -1) {
       InstructorFormData.append(key, value);
    } else
          InstructorDataNoImage = { ...InstructorDataNoImage, [key]: value };
    }



export const MulterFor_InstructorImages = (req, res, next) =\> {
    console.log("MulterFor_InstructorImages Reqbody", req.body);
    let MulterVals = {};

    MulterVals.filepath = "./Public/Institute/Instructors";
    MulterVals.UploadFields = [
        { name: "ProfileImage" },
    
        { name: "TrainerPermitImage" },
        ...(req.body.InstructorLicenseDetails || []).map((license, index) => ({
            name: `LicenseImage_${index + 1}`,
        })),
        ...(req.body.SpecialLicenseDetails || []).map((license, index) => ({
            name: `SLicenseImage_${index + 1}`,
        })),
    ];
    MulterVals.filetypes = [];
    MulterVals.filetypes[0] = "image/png";
    MulterVals.filetypes[1] = "image/jpg";
    MulterVals.filetypes[2] = "image/jpeg";
    MulterVals.filetypes[3] = "image/svg+xml";
    MulterMiddleware(req, res, next, MulterVals);

};

现在如何按MULTER中给出的动态字段名称发送嵌套阵列图像

0 个回答

  • 2 浏览
  • Shuaib Asghar 提出于 2024-03-02 04:58:24

相似问题