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('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?

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