Помогите в чем проблема
const FormData = require(form-data)
const fetch = require(node-fetch)
const path = require("path")
const basePath = process.cwd();
const fs = require("fs");
fs.readdirSync(`${basePath}/build/images`).
forEach(file => {
const formData = new FormData();
const fileStream = fs.createReadStream(`${basePath}/build/images/${file}`);
formData.append("file", fileStream);
let url = '';
let options = {
method: "POST",
headers: {
Authorization: '',
},
body: formData
};
fetch(url, options)
.then((res) => res.json())
.then((json) => {
const filename = path.parse(json.file_name).name;
let rawdata = fs.readFileSync(`${basePath}/build/json/${filename}.json`)
let metadata = JSON.parse(rawdata);
metadata.file_url = json.ipfs_url
fs.writeFileSync(`{basePath}/build/json/${filename}.json`, JSON.stringify(metadata, null, 2));
console.log(`${json.file_name} uploaded & ${filename}.jsonupdated!`);
})
.catch((err) => console.error('error:' + err));
})
-
Вопрос задан
-
56 просмотров