Can't pass the value of result.public_id after submitting the image.
Hello!
I used the script suggested here: https://cloudinary.nuxtjs.org/examples/upload
Please tell me how can I pass the result.public_id value through $emit? Now it is not available inside the response function.
Response: Uncaught (in promise) TypeError: Cannot read properties of undefined (reading '$ emit')
Or can I use another way to pass this value to another companet?
thank you.
async selectFile(e) {
const file = e.target.files[0];
if (!file) return;
const readData = (f) => new Promise((resolve) => {
const reader = new FileReader();
reader.onloadend = () => resolve(reader.result);
reader.readAsDataURL(f);
});
const data = await readData(file);
const instance = this.$cloudinary.upload(data, {
folder: this.id_user,
uploadPreset: 'rlc1cg8y'
}, function (error, result, vm) {
console.log(result, error);
if (!error && result) {
this.$emit('public_id', result.public_id); // Uncaught (in promise) TypeError: Cannot read properties of undefined (reading '$emit')
}
});
}
0
-
Hi Aleksandr,
After the file is uploaded to your account, the upload method would return a promise which contains an Asset with all the asset's information including the public_id, or an Error if the upload failed.
For example:
const asset = await this.$cloudinary.upload(file, {
upload_preset: 'my_preset',
});
console.log (asset);Let us know if you have any further questions.
0
Post is closed for comments.
Comments
1 comment