Closed joydmukherjee closed 1 year ago
It looks like you may want
const cid = await client.storeDirectory(files)
instead of
const cid = await client.storeDirectory([formfields]);
If I'm reading that right, formfields
contains the unparsed form data?
@joydmukherjee did this fix things for you?
@joydmukherjee Closing this for lack of activity. In case you are still hitting issues please re-open and let us know :)
Hi I am trying to use Next.js api routes to store an image file on NFT.storage. I am taking an image as an input from the user in the browser and passing that to the api file using Axios and FormData
const formData = new FormData(); formData.append('image', imageUrl); const cid = await axios.post('api/uploadNFTData', formData);
here the imageUrl is event.target.files[0] and in the api folder I have uploadNFTData.js containing this code I have done this to keep my API key more secure by taking the value from the .env ` import { NFTStorage, File, Blob } from 'nft.storage'; import formidable from 'formidable'; const client = new NFTStorage({ token: process.env.NFT_STORE_TOKEN}); // first we need to disable the default body parser export const config = { api: { bodyParser: false, }, } export default async function uploadNFTData(req,res) { const form = new formidable.IncomingForm(); form.uploadDir = "./"; form.keepExtensions = true; var formfields = await new Promise(function (resolve, reject) { form.parse(req, (err, fields, files) => { if (err) { reject(err); return; } resolve(files); console.log("within form.parse method, subject field of fields object is: " + files);try{ const cid = await client.storeDirectory([formfields]); res.status(200).json({ message: cid });
}catch(err){ res.status(500).json({ message: "could not upload data" }); } } `
Now I am getting the following error on server side error - TypeError: blob.stream is not a function Can someone please help regarding what I am doing wrong?? Or This kind of call cannot be done??