[SOLVED] I having trouble sending the image to ipfs using Moralis

When I send a picture from a browser to a server Moralis (API) i get , this error :

Uncaught (in promise) TypeError: Cannot create a Parse.File with that data.

ParseFile moralis.js:12787

For the record, the image I sent is readable using fs nodejs

Is there any solution?

What is the code that you are using? I didn’t see that error before. Is the data encoded in base64?

1 Like

I am transferring the image from the server ( Node.js ) to the browser , and then send it from the browser to moralis :

server node.js
var photo = fs.readFileSync("…/nfts/resulte/photos/"+aData[nd].replace(".json",".png"), {encoding: ‘base64’})
socket.emit(“res”,{photo : photo})

browser :
socket.on(“res”, d => {
const imageFile = new Moralis.File(“image name”, d.photo)
await imageFile.saveIPFS();
let imageHash = imageFile.hash();

})

I get this erorr : Uncaught (in promise) TypeError: Cannot create a Parse.File with that data.
ParseFile moralis.js:12787
setTYhis main.js:40
main.js:38
emit index.js:143
emitEvent socket.js:276
onevent socket.js:263
onpacket socket.js:228
emit index.js:143
ondecoded manager.js:200
emit index.js:143
add index.js:110
ondata manager.js:192
emit index.js:143
onPacket socket.js:323
emit index.js:143
onPacket transport.js:100
onData transport.js:92
onmessage websocket.js:76
addEventListeners websocket.js:76
doOpen websocket.js:61
open transport.js:44
probe socket.js:270
onOpen socket.js:290
onHandshake socket.js:344
onPacket socket.js:308
emit index.js:143
onPacket transport.js:100
callback polling.js:83
onData polling.js:86
emit index.js:143
onData polling-xhr.js:188
onLoad polling-xhr.js:229
onreadystatechange polling-xhr.js:147
initApp main.js:98
login main.js:86
main.js:143
moralis.js:12787:15

You may need to specify that the data is in base64 format as a parameter to Moralis.file

1 Like

I tried that but it didn’t work

You are a great engineer, it worked :heart:

I changed the code in browser to
const imageFile = new Moralis.File(data.custom_fields.number_photo, { base64: photo})

After I sent the image to ipfs and then sent the metadata to ipfs, the transmission succeeded and I got a response .
But when I sent the metadata to Moralis.Plugins.rarible.lazyMint I got this error :

MetaMask - RPC Error: Provided chainId “4” must match the active chainId “1”
[inpage.js:1:51626]

and I got this error :
Uncaught (in promise) Error: Provided chainId “4” must match the active chainId “1”
moralis.js:6355
tryCatch moralis.js:44099


moralis.js:6355:45

setTYhis()

async function setTYhis() {

    const imageFile = new Moralis.File(data.custom_fields.number_photo, { base64: photo })

    await imageFile.saveIPFS();

    let imageHash = imageFile.hash();

    console.log(imageFile.ipfs())

    let metadata = {

        name: data.name,

        description: data.description,

        image: "/ipfs/" + imageHash

    }

    const jsonFile = new Moralis.File("metadata.json", { base64: btoa(JSON.stringify(metadata)) });

    await jsonFile.saveIPFS();

    let metadataHash = jsonFile.hash();

    console.log(metadataHash)

    await Moralis.Plugins.rarible.lazyMint({

        chain: 'rinkeby',

        userAddress: '0x3251c5883b7B8B2f830f5E299Ae0C93a9B32bD48',

        tokenType: 'ERC1155',

        tokenUri: 'ipfs://' + metadataHash,

        supply: 1,

        royaltiesAmount: 5, // 0.05% royalty. Optional

        list: true, // Only if lazy listing

        listTokenAmount: 1, // Only if lazy listing

        listTokenValue: 10 ** 18, // Only if lazy listing

        listAssetClass: 'ETH', // only if lazy listing  || optional

    })

    resDiv.innerHTML = " done! ";

    setTimeout(() => {

        // next one

    }, 1000)

}

you can create a separate forum thread about this problem with Moralis.Plugins.rarible.lazyMint, also make sure that you have latest version of rarible plugin

Yes, I have the latest version of rarible plugin

I created a separate forum thread about this problem