首页 > 解决方案 > 从 BASE 64 编码重新创建 Excel 文件

问题描述

我有一个将 Excel 文件发送到服务器的客户端(React Client - with DropZone)

 const onDrop = useCallback(acceptedFiles => {

    // ... Some code 

    const reader = new FileReader();
    reader.onabort = () => console.log("file reading was aborted");
    reader.onerror = () => console.log("file reading has failed");
    reader.onload = async () => {
      // Send file the Server
      const result = reader.result;
      const body = {
        url: result
      };

      await axiosInstance.post("/api/upload", body);
    };

    acceptedFiles.forEach(file => reader.readAsDataURL(file));
  }, []);

Node JS 服务器将其接收为:

router.post("/", async (req, res) => {

  // ... Some code 
  console.log(req.body.url);

}

req.body.url:

data:application/vnd.ms-excel;base64,0M8R4KGxGuEAAAAAAAAAAAAAAAAAAAAAPgADAP7/CQAGAAAAAAAAAAAAAAADA ...

如何创建与客户端相同的 Excel 文件?

标签: javascriptnode.jsbase64

解决方案


推荐阅读