Node.js 如何以单个已知格式发布不同格式的文件内容\struct

Node.js 如何以单个已知格式发布不同格式的文件内容\struct,node.js,angular,base64,filereader,Node.js,Angular,Base64,Filereader,使用angular8+node.js-尝试找出如何获取(post)文件内容-无论是什么格式(UTF8或base64或binary,在我的情况下)到node middlewear函数,因此之后我可以将其编码(如果需要)为base64格式\结构。 当文件内容为base64时,我成功地做到了这一点,但当文件内容为二进制时,就会遇到麻烦 请参阅我的代码: 客户端://modalRef.componentInstance是模式窗口的引用,用于批准上载文件 modalRef.componentInsta

使用angular8+node.js-尝试找出如何获取(post)文件内容-无论是什么格式(UTF8或base64或binary,在我的情况下)到node middlewear函数,因此之后我可以将其编码(如果需要)为base64格式\结构。 当文件内容为base64时,我成功地做到了这一点,但当文件内容为二进制时,就会遇到麻烦

请参阅我的代码: 客户端://modalRef.componentInstance是模式窗口的引用,用于批准上载文件

  modalRef.componentInstance.passResult.subscribe(result => 
  {
    if (result)
    {
      let fileReader = new FileReader();
      fileReader.onload = () => 
      {

        this.uploadFileContent(fileReader.result.toString());
      }
      fileReader.readAsText(event.target.files[0]);
      //fileReader.readAsText(event.target.files[0], "ascii");

    }
    event.target.value = null;
    this.FileToUpload = null;
  });
这是uploadFileContent方法:

uploadFileContent(fileContent : /*string*/any)
{
    this.dataService.uploadFile(fileContent).subscribe();
}
这是服务方法:

uploadFile(fileContent : /*string*/any) : Observable<any>
{
  let body =  
  { 
    file: fileContent
  };    
  return this.http.post<any>(<fileUploadUrl>, body, {
    withCredentials:true
  }).pipe(
    tap(res=>{
      console.log('file was uploaded!'); 
    }),
    catchError(error =>  this.doSomething(error))
  ); 
}

只需将文件作为二进制字符串发布即可解决此问题。 而不是: fileReader.readAsText(event.target.files[0])

我用过:

fileReader.readAsBinaryString(event.target.files[0])

router.use(schemaValidation(schema), (req, res, next) =>
{
   try
   {
       let file = req.body.file;
       //When receiving the file content in a single fortmat and struct - I would like to encode it 
         base64 format