简体   繁体   English

如何将数据数组对象转换为文件 JSON 并使用该文件向 ReactJS 中的 S3 服务器发送请求?

[英]How to convert data array object to file JSON and use this file to send requests to the S3 server in ReactJS?

EX: const jsonData = [{ age: 12, name: 'Someone' }];例如: const jsonData = [{ 年龄:12,姓名:'某人' }]; And i want convert jsonData to file JSON and use this file to send request to the S3 sever.我想将 jsonData 转换为文件 JSON 并使用此文件将请求发送到 S3 服务器。

I don't think you can do something like that, I believe writing to file using react is not quite straight forward refer: this我不认为你可以做这样的事情,我相信使用 react 写入文件并不是很直接的参考: this

Refer node solution here 在此处参考节点解决方案

Well, what do you mean 'use this file to send request'?好吧,你是什么意思'使用这个文件发送请求'? Do you want to store the created JSON file in S3?是否要将创建的 JSON 文件存储在 S3 中? then pls do it in the backend.然后请在后端进行。

Ok... the S3 thing is a big complicated for such a short question, but in general you can do something like this...好的......对于这么短的问题,S3 的事情很复杂,但总的来说你可以做这样的事情......

fs.writeFile("../../pathToFile.json", yourJSON, 'utf8', (err) => {
    if (err) {
        console.log("Ahh mother****");
        return console.log(err);
    }
    console.log("Now I have to send it to S3");
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM