#Error400 BAD REQUEST ERROR WHILE UPLOADING NFT

Getting this error while uploading NFT. When clicked on create NFT, it shows axios cors error bad request 400! PLEASE HELP

External Image

const projectId = “XXXX”;
const projectSecret = “XXXX”;
const subdomain = “https://nftmarket1012.infura-ipfs.io”;
const authorization = Basic ${Buffer.from(${projectId}:${projectSecret}).toString("base64")};

const client = ipfsHttpClient({
host: “infura-ipfs.io”,
port: 5001,
protocol: “https”,
headers: {
authorization: authorization,
},
});

import {
marketplaceAddress
} from ‘…/config’

import NFTMarketplace from ‘…/artifacts/contracts/NFTMarketplace.sol/NFTMarketplace.json’

export default function CreateItem() {
const [fileUrl, setFileUrl] = useState(null)
const [formInput, updateFormInput] = useState({ price: ‘’, name: ‘’, description: ‘’ })
const router = useRouter()

async function onChange(e) {
const file = e.target.files[0]
try {
const added = await client.add(
file,
{
progress: (prog) => console.log(received: ${prog})
}
)
const url = https://nftmarket1012.infura-ipfs.io/${added.path}
setFileUrl(url)
} catch (error) {
console.log('Error uploading file: ', error)
}
}
async function uploadToIPFS() {
const { name, description, price } = formInput
if (!name || !description || !price || !fileUrl) return
/* first, upload to IPFS /
const data = JSON.stringify({
name, description, image: fileUrl
})
try {
const added = await client.add(data)
const url = https://nftmarket1012.infura-ipfs.io/${added.path}
/
after file is uploaded to IPFS, return the URL to use it in the transaction */
return url
} catch (error) {
console.log('Error uploading file: ', error)
}
}

1 Like

Hi there,

Could you please try the following change in your code:


const client = create({
    host: 'ipfs.infura.io',
    port: 5001,
    protocol: 'https',
    headers: {
        authorization: auth,
    },
});

Additionally, could you please share the source of the tutorial you were following?

2 Likes

This change did solve our issue! Thanks

2 Likes

This topic was automatically closed after 30 days. New replies are no longer allowed.