Upload Widget - Can't add context/metadata with prepareUploadParams()
I'm trying to get the following snippet to dynamically add context/metadata to an upload through the upload widget. It needs to be dynamic because it will be pulling data from fields filled out by the user for each upload. But none of this context/metadata from this test code seems to actually get uploaded with the image, what am I doing wrong with this code?
prepareUploadParams: (cb, params) => {
params["context"] = {
"alt": "@tester, https://example.com/",
"instagram": "@example",
"website": "https://example.com/",
"email": "a@example.com"
};
cb(params);
}
And here is the full function that snippet is from
const myWidget = cloudinary.createUploadWidget(
{
cloudName: "<redacted>",
uploadPreset: "<redacted>",
folder: "public-upload-tester",
cropping: true,
sources: [
"local",
"url",
"camera",
"facebook",
"instagram",
"google_drive",
"dropbox"
],
tags: ["user-uploads", "public-upload-tester-content"],
prepareUploadParams: (cb, params) => {
params["context"] = {
"alt": "@tester, https://example.com/",
"instagram": "@example",
"website": "https://example.com/",
"email": "a@example.com"
};
cb(params);
}
},
(error, result) => {
if (!error && result && result.event === "success") {
console.log("Done! Here is the image info: ", result.info);
}
}
);
jQuery("#upload_widget").click(function(){
myWidget.open();
});
1
-
Hi there,
Thanks so much for reaching out. You are almost there. You just have some incorrect syntax.
I tried the code below and was able to upload an image and see the contextual metadata correctly applied.
prepareUploadParams: (cb, params) => {
params= {
context: "alt=@kitty, https://meow.com/ |
instagram=@meowKitty |
website=https://meowKitty.com/ |
email=meowKitty@example.com",
};
cb(params);
}Could you give that a shot and let me know how it goes?Kind Regards,Tia0
Post is closed for comments.
Comments
1 comment