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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Silverstripe 3.0.2 - UploadField 400 Bad Request


Go to End
Reply


11 Posts   2806 Views

Avatar
pinkp

Community Member, 168 Posts

27 February 2013 at 10:31pm

Edited: 02/05/2013 11:05am

thanks, but that didn't help. I still just get "Bad Request" I don't get how I'm meant to debug this..

FIX
I moved all my files to a new site and finally found the drag and drop stopped when i updated my custom Page.php
It didnt like:

public static $has_one = array(
   'MenuImg' => 'Image'

   );
   public function getCMSFields() {

   $fields = parent::getCMSFields();
   
   $uploadField = new UploadField('MenuImg', 'Menu Image');
   $fields->addFieldToTab('Root.MenuImage', $uploadField);
   $uploadField->setFolderName('menuphotos');

   return $fields;
}

this created a 'bad request' so removed the code and reworked it for another page type and it works..

EDIT
So I get this Bad Request error by having Image Upload fields in my Page.php code
This is my code, can any body see what im doing wrong or suggest how to have these fields on every page another way?

<?php
class Page extends SiteTree {

   public static $db = array(
   'Ad1Link' => 'Text',
   'Ad2Link' => 'Text',
   'Ad3Link' => 'Text',
   'Ad1Title' => 'Text',
   'Ad2Title' => 'Text',
   'Ad3Title' => 'Text'
   );
public static $has_one = array(
   'Ad1' => 'Image',
   'Ad2' => 'Image',
   'Ad3' => 'Image'

);
public function getCMSFields() {

   $fields = parent::getCMSFields();
   
   $fields->addFieldToTab('Root.Adverts',$uploadField = new UploadField($name = 'Ad1',$title = 'Advert 1 (239px X 165px)'));
   $fields->addFieldToTab('Root.Adverts', TextField::create('Ad1Link','Advert 1 Link'));
   $fields->addFieldToTab('Root.Adverts', TextField::create('Ad1Title','Advert 1 Title'));
   
   $fields->addFieldToTab('Root.Adverts',$uploadField = new UploadField($name = 'Ad2',$title = 'Advert 2 (239px X 165px)'));
   
   $fields->addFieldToTab('Root.Adverts', TextField::create('Ad2Link','Advert 2 Link'));
   $fields->addFieldToTab('Root.Adverts', TextField::create('Ad2Title','Advert 2 Title'));
   
   $fields->addFieldToTab('Root.Adverts',$uploadField = new UploadField($name = 'Ad3',$title = 'Advert 3 (239px X 165px)'));
   $fields->addFieldToTab('Root.Adverts', TextField::create('Ad3Link','Advert 3 Link'));
   $fields->addFieldToTab('Root.Adverts', TextField::create('Ad3Title','Advert 3 Title'));

   return $fields;
}

}

class Page_Controller extends ContentController {

   /**
    * An array of actions that can be accessed via a request. Each array element should be an action name, and the
    * permissions or conditions required to allow the user to access it.
    *
    * <code>
    * array (
    * 'action', // anyone can access this action
    * 'action' => true, // same as above
    * 'action' => 'ADMIN', // you must have ADMIN permissions to access this action
    * 'action' => '->checkAction' // you can only access this action if $this->checkAction() returns true
    * );
    * </code>
    *
    * @var array
    */
   public static $allowed_actions = array (
   );

   public function init() {
      parent::init();

      // Note: you should use SS template require tags inside your templates
      // instead of putting Requirements calls here. However these are
      // included so that our older themes still work
      Requirements::themedCSS('reset');
      Requirements::themedCSS('layout');
      Requirements::themedCSS('typography');
      Requirements::themedCSS('form');
   }
}

EDIT 2

So if I remove my has_one images from the code I no longer get a bad request when drag and dropping other images and data on the site. This seems to be directly relate to the fact its in my Page.php code... any ideas what I should do?

Avatar
RobboDev

Community Member, 21 Posts

3 June 2013 at 3:12pm

Don't know if its related to your issue, but i found that the problem was my DataObject (an extension of SiteConfig) that I was adding the Image relation to, had not been saved initially. So after clicking save, then I was able to upload an image.

Good luck

Avatar
Spambanjo

Community Member, 18 Posts

28 September 2013 at 12:31am

Thanks RobboDev.

Clicking "Save" before trying an upload after adding an image field to the site config works for me and has solved my problem.

Go to Top