0

EX: const jsonData = [{ age: 12, name: 'Someone' }]; And i want convert jsonData to file JSON and use this file to send request to the S3 sever.

Hamist1001
  • 43
  • 4

2 Answers2

0

I don't think you can do something like that, I believe writing to file using react is not quite straight forward refer: 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? then pls do it in the backend.

Mouleesh Guru
  • 55
  • 1
  • 10
0

Ok... the S3 thing is a big complicated for such a short question, but in general you can do something like this...

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");
});
  • I have an error when using fs " fs.writefile is not a function" and I use browserify-fs but it have the same error. – Hamist1001 May 11 '22 at 07:26