• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Creating attachment from generated data

Teapot

Well-known member
#1
I could do with a little guidance from someone more familiar with the attachment system than me. Basically, I want to save an image I've generated programatically into the attachment system.

The image itself is a fully-formed Imagick-generated PNG file, and can be downloaded directly from the controller. However, I'd like to allow the user to save it to the site to access later, and I'd ideally like to leverage the attachment system and all the various benefits it offers me over saving the image manually.

Has anyone tried to use the attachment system this way? Is it feasible, and if so, where would you recommend I start?

As always, thank you for your time.
 

Jeremy

Well-known member
#4
Attachments don't need to be associated with posts. They need to be associated with a content type, but it's not required to be posts (ie, conversation messages).
 

digitalpoint

Well-known member
#5
I think attachments needs to be associated with a content type. Correct me if I'm wrong.
Yep... you can see how XenForo manages the attachment <-> content type relationship in the xf_content_type_field table. That's where you define the attachment handler class for the content type.

You can also see how attachment handlers work by checking the library/XenForo/AttachmentHandler/ directory (that's where the handlers are for posts and conversations).