I am facing an issue with my file upload function. After the file is uploaded, it returns the uploaded path which I then pass to a TinyURL function
this.tinyUrl.shorten(data.url).subscribe(sUrl => { shortUrl=sUrl;});
. However, there is a delay in receiving the sUrl
and the subsequent code gets executed before that. I want to ensure that the next code is not executed until the sUrl
is returned.
handleUpload(file) {
let promise = new Promise((resolve, reject) => {
const contentType = file[0].type;
const bucket = new S3(
{
.....
}
);
.....
bucket.upload(params, (err, data)=> {
if (err) {
return false;
} else {
if (data.url) {
this.tinyUrl.shorten(data.url).subscribe(sUrl => {
shortUrl=sUrl;
});
}
resolve(this.FileUploadImage);
}
});
setTimeout(() => {
}, 4000);
});
}
If anyone has a solution, I would appreciate it. Thank you!