I am currently building an NFT-related app and currently trying to mint the NFT using a test network. I am trying to upload the image file to ipfs.
To upload an image, I am currently using a dropzone to get the file:
const client = ipfsHttpClient('https://ipfs.infura.io:5001/api/v0');
const CreateItem = () => {
const uploadToInfura = async (file) => {
try {
const added = await client.add({ content: file });
const url = `https://ipfs.infura.io/ipfs/${added.path}`;
setFileUrl(url);
} catch (error) {
console.log('Error uploading file: ', error);
}
};
const onDrop = useCallback(async (acceptedFile) => {
await uploadToInfura(acceptedFile[0]);
}, []);
const {
getRootProps,
getInputProps,
isDragActive,
isDragAccept,
isDragReject,
} = useDropzone({
onDrop,
accept: 'image/*',
maxSize: 5000000,
});
const fileStyle = useMemo(
() => `dark:bg-nft-black-1 bg-white border dark:border-white border-nft-gray-2 flex flex-col items-center p-5 rounded-sm border-dashed
${isDragActive ? ' border-file-active ' : ''}
${isDragAccept ? ' border-file-accept ' : ''}
${isDragReject ? ' border-file-reject ' : ''}`,
[isDragActive, isDragReject, isDragAccept],
);
return (
<div className="flex justify-center sm:px-4 p-12">
<div className="w-3/5 md:w-full">
<h1 className="font-grotesque text-white text-2xl">
Create new item
</h1>
<div className="mt-16">
<p className="font-grotesque dark:text-white text-nft-black-1 text-xl">
Upload file
</p>
<div className="mt-4">
<div {...getRootProps()} className={fileStyle}>
<input {...getInputProps()} />
<div className="flexCenter flex-col text-center">
<p className="font-grotesk dark:text-white text-nft-black-1 text-xl">
JPG, PNG, GIF, SVG, WEBM, MP3, MP4. Max 100mb.
</p>
<p className="font-poppins dark:text-white text-nft-black-1 font-grotesk text-sm">
Drag and Drop File
</p>
</div>
</div>
</div>
</div>
</div>
</div>
);
};
export default CreateItem;
Above is a simplified version of my component. I am attempting to pass the file as a prop to my own upload to infura method.
The program was working fine however when attempting to use the platform today I kept running into the same error.
Whenever an attempt to upload was made the POST request fails. This is the error logged:
ipfs.infura.io:5001/api/v0/add?stream-channels=true&progress=false:1 Failed to load resource: the server responded with a status of 401 (Unauthorized)
fetch.browser.js?c17b:106 POST https://ipfs.infura.io:5001/api/v0/add?stream-channels=true&progress=false 401 (Unauthorized)
I am connected to wifi and within the file size limit. Is anyone familiar with this error?