Moralis save file url

Howdy, i got to get some sleep so i thought i would ask here.
I am trying to get the save file url but its not useable for me.

i get an options function back and not sure what to do with it.

    const inputImage = document.getElementById("input_image").value.split("\\");
    const inputImageName = inputImage[inputImage.length - 1];
    const imageFileUploadControl = $("#input_image")[0];
    if (imageFileUploadControl.files.length > 0) {
        const file = imageFileUploadControl.files[0];
        const imageFile = new Moralis.File(inputImageName, file);
        await imageFile.save()
        musix.image = imageFile.url;
        console.log(imageFile);
        console.log(musix.image);
    } else {
        console.log(musix.image);
    }

Thanks, i should be up in a few hours.

It looks like you have _url in that object

i got it set up for saveIPFS() now and get

Æ’ () {
      return this._ipfs;
    }

i need the string, any ideas? im still kind of new to javascript.

you can print the object with console.log(JSON.stringify(file_object)) and after that you will see what you have to access

musix.image = JSON.parse(JSON.stringify(imageFile)).ipfs;
i needed to parse the json string to get the part i wanted.
thanks. i can sleep now :slight_smile:

hi! you are really interesting information and good question. but i am not idea.

The function was called by the JSON.stringify and the was able to phase as a json with the JSON.parse if I understand this right.

There is something about the served up ‘ParseFile’ i don’t quite get but it works now. thanks for the help.

Ran in to another snag. is there a way to program a way to save to a path like https://hpx8y0dei8ui.usemoralis.com/json/0xb31BE65A14F125e36396e1a491E9ac8C7A7227bE/0000000000000000000000000000000000000000000000000000000000000002.json
?

i know i can deploy using a terminal but i haven’t learned how to do it with the sdk yet

I don’t know of a way to do that from Moralis SDK, you can do it with moralis-admin-cli from terminal, but you already know how to do it from terminal

this got me where i needed to.


https://musix-site-t8i43.ondigitalocean.app/

2 Likes