Error using "await metadataFile.saveIPFS({useMasterKey:true})"

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('[email protected]/dist/web3.min.js', function() {
				$.getScript('', function() {
					// connect to Moralis server
					Moralis.serverURL = "";
					// Save file input to IPFS
					const data = $('#upload-image').get(0).files[0]
					const file = new Moralis.File(, data)
					await file.saveIPFS( {useMasterKey:true} );
					console.log(file.ipfs(), file.hash());

Any idea what is wrong?

I don’t know exactly why it doesn’t recognise that function as async.

anyway, this will not work from a browser window (that master key usage), you’ll have to authenticate to be able to save to IFPS from browser, or to use a cloud function, but we may have a problem currently with using .saveIPFS from a cloud function