Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

How to Update the Existing image in mongo

Avatar

Level 3

Hi All,

I am storing the images in the mongo, I referenced this post to store image in mongo

http://help-forums.adobe.com/content/adobeforums/en/experience-manager-forum/aem-communities.topic.h...

I observed that when someone edit the resource to change the image ,instead of updating the same image in mongo, it creates the new entry.

I want to update the same image when that image gets changed from request. I tried updating the imagestream using ValueMap, but that does not work

final ModifiableValueMap modProps = imageResource.adaptTo(ModifiableValueMap.class); modProps.put("nt:file", jpegStream);

Does anyone know how to update the existing image uploaded in mongo?

Thanks,

Monika

1 Accepted Solution

Avatar

Correct answer by
Level 1

Hello,

So, updating attachments isn't really something that was built into the product underneath the hood. Every time an attachment needs to be changed, the old one gets deleted, the new one gets created, and the social:attachments property of the parent resource gets updated to point to the new attachment. To the user, it looks like a true update, but for you as the implementer you're going to need to follow that same replacement process.

I'm on the team that built the storage system for user-generated content, and that's how we decided to do it. Actually changing the binary data was tricky to make work across different storage platforms and we couldn't see a benefit gained by doing it that way anyway.

Hope that helps!

Mason

View solution in original post

3 Replies

Avatar

Correct answer by
Level 1

Hello,

So, updating attachments isn't really something that was built into the product underneath the hood. Every time an attachment needs to be changed, the old one gets deleted, the new one gets created, and the social:attachments property of the parent resource gets updated to point to the new attachment. To the user, it looks like a true update, but for you as the implementer you're going to need to follow that same replacement process.

I'm on the team that built the storage system for user-generated content, and that's how we decided to do it. Actually changing the binary data was tricky to make work across different storage platforms and we couldn't see a benefit gained by doing it that way anyway.

Hope that helps!

Mason

Avatar

Level 3

masonw13300227 wrote...

Hello,

So, updating attachments isn't really something that was built into the product underneath the hood. Every time an attachment needs to be changed, the old one gets deleted, the new one gets created, and the social:attachments property of the parent resource gets updated to point to the new attachment. To the user, it looks like a true update, but for you as the implementer you're going to need to follow that same replacement process.

I'm on the team that built the storage system for user-generated content, and that's how we decided to do it. Actually changing the binary data was tricky to make work across different storage platforms and we couldn't see a benefit gained by doing it that way anyway.

Hope that helps!

Mason

 

Thanks Mason that helps!!

Avatar

Level 3

masonw13300227 wrote...

Hello,

So, updating attachments isn't really something that was built into the product underneath the hood. Every time an attachment needs to be changed, the old one gets deleted, the new one gets created, and the social:attachments property of the parent resource gets updated to point to the new attachment. To the user, it looks like a true update, but for you as the implementer you're going to need to follow that same replacement process.

I'm on the team that built the storage system for user-generated content, and that's how we decided to do it. Actually changing the binary data was tricky to make work across different storage platforms and we couldn't see a benefit gained by doing it that way anyway.

Hope that helps!

Mason

 

Hi Mason,

Its been long though that I implemented the same logic of updating the image in mongo as you specified i.e. Delete the image first and then add it back again.

But with this we are facing an issue, that when we upload the new image from front-end , it does not display the new image on the page without refreshing the page. Our requirement is that pop up gets opened where you can upload the new image

and when you click ok, It should show the new image on page (uploading the new image to mongo is a ajax call to servlet) without refreshing the page.

While debuging it seems to me that, deletion of the image completely  in mongo is taking time (chunks and files) , but it returns back with the status that it got deleted and creates the new entry with the same path.

Have you faced this issue earlier, If yes how we can resolve this?

Thanks,

Monika