<!-- Moralis SDK code -->
<script src="https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js"></script>
<script src="https://unpkg.com/moralis/dist/moralis.js"></script>
<h1>IPFS DEMO</h1>
<button id="btn-login">Login</button><br><br>
<input type="text" name="metadataname" id="metadataname" placeholder="name"><br><br>
<textarea name="metadatadescription" id="metadatadescription" cols="30" rows="10"></textarea><br>
<input type="file" name="fileInput" id="fileInput"><br><br>
<button onclick=Go()>Go</button>
<script>
// connect to Moralis server
const serverUrl = "...............";
const appId = "........";
Moralis.start({ serverUrl, appId});
//login
login = async () => {
Moralis.authenticate().then(function (user) {
console.log('logged in');
})
}
//upload image
uploadimage = async() => {
const data = fileInput.files[0];
const file = new Moralis.File(data.name, data);
await file.saveIPFS();
console.log(file.ipfs(), file.hash());
return file.ipfs();
}
//upload metadata object name description image
uploadmetadata = async(imageURL)=>{
const name =document.getElementById('metadataname').value;
const description =document.getElementById('metadatadescription').value;
const metadata = {
"name" :name,
"description" : description,
"image" : imageURL
}
const file = new Moralis.File("file.json" ,{base64 : btoa(JSON.stringify(metadata))});
await file.saveIPFS({useMasterKey:true});
console.log(file.ipfs());
}
//go function
Go = async()=> {
const image =await uploadimage();
await uploadmetadata(image);
}
</script>
What is wrong in these code, I tried the {usemasterkey:true} this solution then also not working.
Can anyone please let me know what is issue.