First of all, I’m new to js and I’m using vanilla js. I’m trying to upload files to IPFS without having to authenticate. So I saw this post -> [SOLVED] File upload by public is disabled with node js and it says to do this -> await metadataFile.saveIPFS({useMasterKey:true});
And after doing that I’m getting the error “Uncaught SyntaxError: await is only valid in async functions and the top level bodies of modules”
My code is this.
$( "#upload-image" ).change( async function() {
var selected = $( this )[0].files.length;
if ( ! selected ) return false;
$.getScript('https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js', function() {
$.getScript('https://unpkg.com/moralis/dist/moralis.js', function() {
// connect to Moralis server
Moralis.initialize("o9YG2udd965Io7qhV....");
Moralis.serverURL = "https://e8bqs.....usemoralis.com:2053/server";
// Save file input to IPFS
const data = $('#upload-image').get(0).files[0]
const file = new Moralis.File(data.name, data)
await file.saveIPFS( {useMasterKey:true} );
console.log(file.ipfs(), file.hash());
});
});
Any idea what is wrong?