Node.js 将zip文件从reactjs上载到nodejs

Node.js 将zip文件从reactjs上载到nodejs,node.js,reactjs,express,axios,jszip,Node.js,Reactjs,Express,Axios,Jszip,我正在建立一个传输文件网站,我面临一个大问题! 我正在使用react.jsexpress.js和数字海洋空间。 当我将文件拖到拖放区并点击submit时,文件应该上传到digital ocean spaces上,就像amazon s3一样。 所以,现在我可以毫无问题地上传一个文件了,但是,如果我能在通过Express将文件发送到digital ocean之前将其压缩到react上,那就更好了。这就是问题所在!我无法发送压缩文件!我已经用postman测试了zip文件的发送,它可以正常工作,但是当

我正在建立一个传输文件网站,我面临一个大问题! 我正在使用
react.js
express.js
和数字海洋空间。 当我将文件拖到拖放区并点击submit时,文件应该上传到digital ocean spaces上,就像amazon s3一样。 所以,现在我可以毫无问题地上传一个文件了,但是,如果我能在通过Express将文件发送到digital ocean之前将其压缩到react上,那就更好了。这就是问题所在!我无法发送压缩文件!我已经用postman测试了zip文件的发送,它可以正常工作,但是当我尝试使用axios从客户端(react)发送它时,什么都没有发生。
请需要帮助:(已经三天了,我一直在寻找如何使它工作,但没有办法。 非常感谢你们

Upload.js组件客户端(react):


最后我找到了解决方案,我的方法可能是正确的,但同时这个在前端使用JSZIP的解决方案限制为5Mo/file,而且它的大小非常差。因此,解决方案实际上是在服务器端发送每个文件的相对路径(express)然后,在下载文件时,我使用file archiver压缩我从digital ocean收到的文件,将它们的相对路径直接放在fileObject的append函数上

代码如下:

类文件归档器{

constructor(app, files = [], response) {

    this.app = app;
    this.files = files;
    this.response = response;

}

download(){

    const app = this.app;
    const files = this.files;
    const response = this.response;
    let fullPath = null;
    //const uploadDir = app.get('storageDirectory');
    const zip = archiver('zip');

    response.attachment('download.zip');
    zip.pipe(response);

    const s3Downloader = new S3Download(app, response);

    _.each(files, (file) => {

        fullPath = _.get(file, 'fullPath');
        const fileObject = s3Downloader.getObject(file);
        if(fullPath === null || fullPath === ''){
            zip.append(fileObject, {name : _.get(file, 'originalName')});
        } else {
            zip.append(fileObject, {name : _.get(file, 'fullPath')}); //Here put the absolute path (relative path)
        }


    })

    zip.finalize();

    return this;
}
}

//导出模块 module.exports={ 档案管理员 }

constructor(app, files = [], response) {

    this.app = app;
    this.files = files;
    this.response = response;

}

download(){

    const app = this.app;
    const files = this.files;
    const response = this.response;
    let fullPath = null;
    //const uploadDir = app.get('storageDirectory');
    const zip = archiver('zip');

    response.attachment('download.zip');
    zip.pipe(response);

    const s3Downloader = new S3Download(app, response);

    _.each(files, (file) => {

        fullPath = _.get(file, 'fullPath');
        const fileObject = s3Downloader.getObject(file);
        if(fullPath === null || fullPath === ''){
            zip.append(fileObject, {name : _.get(file, 'originalName')});
        } else {
            zip.append(fileObject, {name : _.get(file, 'fullPath')}); //Here put the absolute path (relative path)
        }


    })

    zip.finalize();

    return this;
}