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.

DataObjectManager Module

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Sean, biapar, Willr, Ingo, swaiba, simon_w

Files can be attached once you have saved the record for the first time


3 Posts   931 Views


4 June 2013 at 11:28am (Last edited: 4 June 2013 11:29am), Community Member, 4 Posts

Hi there,

I'm having issues with SilverStripe backend image upload to a specific dataobject ID.
"Files can be attached once you have saved the record for the first time."

I want to attach the file before creating the record. I've tried using Uploadify but Uploadify has no support for SilverStripe 3. I've tried porting Uploadify for old SilverStripe version to SilverStripe 3 but that was very messy.


Code example for this simple gallery module:


* Gallery & Images DataStructure with ModelAdmin enabled in the CMS.
* ModelAdmin called: Gallery & Images

class Gallery extends DataObject {
static $db = array(
static $has_many = array(
"GalleryImages" => "GalleryImages",

class GalleryImages extends DataObject {
static $db = array(

static $has_one = array(
"Gallery" => "Gallery",
"galleryImage" => "Image",

function getCMSFields() {

$fields = parent::getCMSFields();
$fields->addFieldToTab("Root.Main", $if = new UploadField('galleryImage','Gallery Images'));
$if->setConfig('allowedMaxFileNumber', 500)->setFolderName('gallery/gallaryimg');
$if->getValidator()->setAllowedExtensions(array('jpg', 'jpeg', 'png', 'gif'));
return $fields;

class GalleryImagesModelAdmin extends ModelAdmin {
public static $managed_models = array('Gallery','GalleryImages');
static $url_segment = 'GalleryImages';
static $menu_title = 'Gallery & Images';


Any pointers would be greatly appreciated.


4 June 2013 at 5:07pm Forum Moderator, 5511 Posts

You've got to save the record before you add it (like it says). A patch has added support for uploads


6 June 2013 at 9:18am (Last edited: 6 June 2013 10:28am), Community Member, 4 Posts

Thank you for the pointer! Couldn't find that when I went digging for the fix for this.