Editing an existing resource in Cloudinary
Hello,
I am uploading brochures in Cloudinary. I pass the folder name as well. This works fine when I upload the resource first time.
When I pass the public id I obtained and folder name next time to update an existing resource, it seems to create a folder structure within existing folder in Cloudinary.
Do we need to pass the Folder Name when we want to replace an existing resource ?
Below is the code snippet.
if(brochure.Attachment!=null && brochure.Attachment.Length > 0)
{
ImageUploadParams propertyBrochurePdf = new ImageUploadParams();
propertyBrochurePdf.Folder = _cloudinaryBrochureFolder;
propertyBrochurePdf.PublicId = brochure.Cloudinary_PublicId;
propertyBrochurePdf.File = new FileDescription(brochure.FileName, new MemoryStream(brochure.Attachment));
ImageUploadResult result = _cloudinary.UploadResource(propertyBrochurePdf);
brochure.ViewUrl = result.SecureUri.AbsoluteUri;
brochure.Cloudinary_PublicId = result.PublicId;
brochure.Cloudinary_Url = result.SecureUri.AbsoluteUri;
brochure.ViewUrl = result.SecureUri.AbsoluteUri;
}
Can anyone please advise.
-
Hi Ray,
The folder name should be passed in as well as its part of the public id. For more guidelines, please see the following- https://support.cloudinary.com/hc/en-us/articles/202520852-How-can-I-update-an-already-uploaded-image-
0 -
The Folder name seems to work the very first time. If I pass the Folder Name when re-uploading a brochure, it creates another sub-folder under the folder where the current brochure exists.
0 -
Hi Ray,
It would be easier if we could see the values being passed in the first initial upload and on the reupload. I am particularly interested in the values passed for propertyBrochurePdf.Folder = _cloudinaryBrochureFolder and propertyBrochurePdf.PublicId = brochure.Cloudinary_PublicId. I believe that on the reupload, the original folder is being included again and thus causing the same folder structure to be within the folder. If you don't wish to share the details on this public forum, please open a support ticket at https://support.cloudinary.com/hc/en-us/requests/new and also include the `cloud_name` that the issue is happening on.
0 -
Hi Daniel,
You are right. Here is the flow:-
First Upload:- Folder Name = "qa/Property/Brochure" and Public Id empty string. The Public Id returned is saved.
Lets say the public id returned is "qa/property/brochures/abcdefghijk"
Second Upload:- Folder Name = "qa/Property/Brochure" and Public Id returned from first call, i.e. "qa/property/brochures/abcdefghijk".
Actual result:- A file is created under the folder with path: qa/property/brochures/qa/property/brochures/abcdefghijk.pdf
Expected result: I would expect the file to be at qa/property/brochures and not qa/property/brochures/qa/property/brochures.
My question here is what the best way to re-upload a brochure. It seems like passing just the public id and not passing the folder for re-upload seems to overwrite which was the expected behavior.
0 -
Hi Ray,
I am assuming that in your first upload, you wish to have the public_id be random. If this is the case, the upload logic could look like this:
- If public_id is empty, pass folder name and public id will stay an empty string
- else (public_id not empty), pass in only the public_id (e.g. qa/property/brochures/abcdefghijk)
I believe this what you suggested at the end and seems like the best way to do it.
Hope this helps.
0
Post is closed for comments.
Comments
5 comments