MSRP - How to CRUD image/file attachments?

Avatar

Avatar

Gdubz-57m2mu

Avatar

Gdubz-57m2mu

Gdubz-57m2mu

25-11-2016

Hi all,

Does there exist an example usage of storing/reading an attachment through the SRP API?

With the how-to samples on Github, specifically the TodoMVC sample[1], I've been able to figure out how to CRUD UGC in MongoDB through the SRP API in our custom components. However, I'm really not sure how to, or what the best practices are for, upload image attachments from custom UGC components.

Right now I'm using the same method I wrote for storing the post but one level down, with a random md5 hash of the current timestamp + filename, and storing the image data as a byte array. This just throws it into the same collection as the rest of the UGC though, and just looking at the Storage Configuration options, there's clearly a separate collection just for attachments.

Thanks for any and all help!

[1] https://github.com/Adobe-Marketing-Cloud/aem-communities-todomvc-sample

View Entire Topic

Avatar

Avatar

Gdubz-57m2mu

Avatar

Gdubz-57m2mu

Gdubz-57m2mu

06-12-2016

Thanks again Calvin, that absolutely worked.

Whether it was storing the value as an InputStream instead of a byte array (byte[]) or storing the key as "nt:file" (JcrConstants.NT_FILE), it worked.

 

As an aside... I'm still extremely confused on what some of the key mappings are between Java and MongoDB. For example, "mimetype" all lowercase translates to "content-type" through the SRP API. These pieces are extremely unclear and not straight forward at all. 😞