Jump to:

22975 Posts in 11620 Topics by 2826 members

General Questions

SilverStripe Forums » General Questions » Silverstripe 3.0.2 - UploadField 400 Bad Request

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

Page: 1 2
Go to End
Author Topic: 1957 Views
  • pinkp
    Avatar
    Community Member
    168 Posts

    Re: Silverstripe 3.0.2 - UploadField 400 Bad Request Link to this post

    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?

  • RobboDev
    Avatar
    Community Member
    20 Posts

    Re: Silverstripe 3.0.2 - UploadField 400 Bad Request Link to this post

    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

  • Spambanjo
    Avatar
    Community Member
    14 Posts

    Re: Silverstripe 3.0.2 - UploadField 400 Bad Request Link to this post

    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.

    1957 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.