New Moralis.file(..) not setting correctly?

I am following this guide https://github.com/DanielMoralisSamples/19_MINTNFT/blob/master/app/static/js/logic.js and the docs https://github.com/DanielMoralisSamples/19_MINTNFT/blob/master/app/static/js/logic.js

When using:

const nft = new Moralis.File(file.name, file);
console.log('nft', nft);

The nft is returning:

image

Is that correct? Because when I then use:

await nft.saveIPFS();
 const imageURI = nft.ipfs();

I get Property 'ipfs' does not exist on type 'File'.ts(2339)

it may be a different method now, you can do also a console log for nft after nft.saveIPFS() to see how it looks

Here is the log

    const file = new Moralis.File(data.name, data)
    await file.saveIPFS();

    console.log(file)

you can see there _ipfs that has the link that you want

But the type checking in TS fails, so cant compile. Managed to get around it with:

    const file = new Moralis.File(data.name, data);
    await file.saveIPFS();

    // Save file reference to Moralis
    const jobApplication = new Moralis.Object('NFTs');
    jobApplication.set('name', this.nftForm.value.name);
    jobApplication.set('description', this.nftForm.value.description);
    jobApplication.set('file', file);
    await jobApplication.save();

    // Retrieve file
    const query = new Moralis.Query('NFTs');
    query.equalTo('name', this.nftForm.value.name);
    query.find().then(function ([application]) {
      const ipfs = application.get('file').ipfs();
      const hash = application.get('file').hash();
      console.log('IPFS url', ipfs);
      console.log('IPFS hash', hash);
    });

I’m not sure checking that much early would give desired result when you are still in “saving” sequence, better to use .then(… syntax right behind the save().

no he use await
so the response should be exist… anyway I have checked…
it was the devs type declaration error, they didn’t define the function on File type declaration

Just ignore the type script error, the function is there

const file = new Moralis.File(data.name, data);
await file.saveIPFS();

// @ts-ignore 
console.log(file.ipfs());
1 Like