I can't seem to find a way to access a value from an async value as it always returns undefined, I would like to wait for the function to end and then retrieve the value but it's not working...
async UploadFile(file): Promise<any> {
let ipfsId: any
const fileStream = fileReaderPullStream(file)
await this.ipfs.add(fileStream, { progress: (prog) => console.log(`received: ${prog}`) })
.then((response) => {
ipfsId = response[0].hash
console.log(ipfsId)
return ipfsId
//window.open("localhost:8080/ipfs/" + ipfsId);
//window.open("https://ipfs.io/ipfs/" + ipfsId);
}).catch((err) => {
console.error(err)
})
}
And this is my call:
uploadFile(event) {
const fileSelected: File = event.target.files[0];
(async() => {
this.temp_ipfs_hash = await this.IPFS.UploadFile(fileSelected)
.then((response) => console.log(response))
console.log(this.temp_ipfs_hash)
})()
}
I'd like to access the return value but it's always returning me undefined or error value... Anyone has any idea what I could try here ?
Thank you so much for your time! :)
Edit: I had no idea it was wrong to post images, so sorry, I've changed it! sorry! :(