Answer the question
In order to leave comments, you need to log in
When loading NFT into IPFS, an error occurs ReferenceError: form is not defined at Object. (C:\Users\user\Downloads\hashlips_art_engine1.1?
Help what is the problem
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));
})
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question