saveIPFS() on a saved file

Hello. I want to use saveIPFS() function on an already saved Moralis.File object on the database but it is giving me error.

This is the error:

client.js?06a0:103 TypeError: Cannot read properties of undefined (reading 'format')
    at ParseFile.value (ParseFile.js?08ff:402:1)
    at ParseFile.value (ParseFile.js?08ff:455:1)
    at _callee7$ (index.vue?6ced:855:1)
    at tryCatch (runtime.js?96cf:63:1)
    at Generator.invoke [as _invoke] (runtime.js?96cf:294:1)
    at Generator.eval [as next] (runtime.js?96cf:119:1)
    at asyncGeneratorStep (asyncToGenerator.js?1da1:3:1)
    at _next (asyncToGenerator.js?1da1:25:1)
    at eval (asyncToGenerator.js?1da1:32:1)
    at new Promise (<anonymous>)

All I am doing is create a Moralis.File, upload it to the database, get it on another page and call saveIPFS() on it. Any solutions?

Hey can you show the code? seems like you have something to do with .format from something undefined :raised_hands:

I am just calling file.saveIPFS(), file is the file from the database. It is a Moralis.File object because I can see it when I console log it. I don’t format anything, that should be in Moralis source code.

Hmmm not so sure about it, coz saveIPFS itself shouldn’t give that, but yeah that’s what the error gives off

It’s hard to debug further unless I can see you code there :raised_hands:

While creating:

const file = new Moralis.File(, this.file)
newAsset.set('imageFile', file)

On another page with a button:

const result = await'getAsset', { objectId: this.$route.params.slug })
this.asset = result[0]

await this.asset.attributes.imageFile.saveIPFS()

I can see the file on the database, I can see when I log it. It’s just saveIPFS() is giving the error. Here is the files console log that I am calling saveIPFS() on:

_data: undefined
_hash: undefined
_ipfs: undefined
_metadata: {}
_name: "5cd5b55d12925b6873d7fe27814c7300_1639585597814.jpg"
_previousSave: undefined
_requestTask: undefined
_source: undefined
_tags: {}

You should save it directly to IPFS. And you can save the url for ipfs in the database.

I don’t want to pin every asset that is created, only the ones that will be minted so that’s why I want the saveIPFS() functionality for later. Is there any solution you can recommend? I can try right now.

You can save a file to IPFS directly from cloud code.
There are different options, in one of them you need the data encoded in base64.

You can also use uploadFolder from web3api

Okay so all I need to do is record the file (but not pin it to IPFS), then do it in a later stage (when minting the asset). What would you recommend for this?

it depends on your use case, you can also pin everything to IPFS if there are not too many files