Simulate document upload approved

Sorry @Sandeep_Challa, I m just seeing this.
I do use multer with express and all is being done on backend/server side.

the snipet that worked for me is

const createDwollaCustomerDocument = async (file, customerId, documentType) => {
  try {    
    const customerUrl = `${dwollaApiUrl}/customers/${customerId}`;

    const requestBody = new FormData();
    requestBody.append('file', fs.createReadStream(file.path), {
      filename: file.originalname,
      contentType: file.mimetype,
      knownLength: file.size  
    });
    requestBody.append('documentType', documentType);


  const response = await dwollaClient.post(`${customerUrl}/documents`, requestBody)
  if(!response){
    throw Error("Error uploading document")
  }
  if(response.status = 200)
  {
    let location = response.headers.get('location')
    const lastStringOfLocation = location.substring(location.lastIndexOf("/") + 1, location.length);
    return lastStringOfLocation
  }
  if (response.status = 400){
    return response.body.message
  }
  } catch (error) {
    console.log("Error in customer document:", error)
    return error
  }
}
1 Like