Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Customising the CMS

Attach an image to a new Page/Dataobject


23 Posts   3166 Views


17 October 2012 at 4:53am Community Member, 288 Posts

Ok I've just finished my first stab at solving this.

I'm working from one limited scenario right now, image attached to data object that's related to a page and just one image/data object.
As long as we're dealing with one image it's a has_one and the field is actually present on the data object which makes it simpler.
However even this has proven to be rather tricky. I think I can get the functionality running on pages rather quickly but I think multi upload is going to be hard. I'm not sure if defining a many_many relationship works before the object is actually created and has an ID.

Martin D.

17 October 2012 at 5:00am Community Member, 21 Posts

Sounds good MarcusDalgren. Feel free to post your code, either here or on github (fork the project). I will get into the code once I get some free time.

Optic Blaze

17 October 2012 at 5:02am Community Member, 162 Posts

Hi, someone wrote a gallery module that deals with these issues:
- multiple upload to gallery
- drag and drop ordering
- adding new image with 1 click
- updating multiple files titles at once

I have tried this image gallery and it works well. check it out

Martin D.

17 October 2012 at 5:06am Community Member, 21 Posts

Optic Blaze, so does the module let you upload images even before saving/creating the main page?


17 October 2012 at 5:13am Community Member, 288 Posts

The code I've written so far is available here:
This is still in its early stages so run this on your own risk.

I will have a look at the Image gallery module to see if it actually solves this.


17 October 2012 at 5:31am Community Member, 288 Posts

Ok I've had a look at the module that handles this (bulk upload) and it does indeed provide a solution.
However the way in which its done does have its risks. If you're using it for bulk creation of DO:s with one image attached (my scenario) it actually creates as many new DO:s as images uploaded. As long as you press Cancel & Delete all you're all good but if you would happen to navigate away from the page in some other way you'll have empty DO:s all over the place.

Not the authors fault per se but it really isn't a good solution. You shouldn't have to pre create objects just in case they get saved.

Martin D.

17 October 2012 at 5:35am Community Member, 21 Posts

I had a temporary solution that used the same mechanism but the database ended up having lots of empty records.


17 October 2012 at 5:54am Community Member, 288 Posts

Just had a look at pages and they aren't an issue since pages are created as drafts when you click "Create new". This limits us to DO:s only which is really nice. I haven't tried the multi upload yet but I will be giving that a go tomorrow.