Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG images passed to UploadField given class of File #4469

Closed
jonom opened this issue Aug 3, 2015 · 10 comments
Closed

BUG images passed to UploadField given class of File #4469

jonom opened this issue Aug 3, 2015 · 10 comments
Labels

Comments

@jonom
Copy link
Contributor

jonom commented Aug 3, 2015

If you have a File relation on a DataObject and upload an image to it through UploadField, the file is incorrectly recorded as a File in the database rather than an Image. This is present in 3.1 and master, probably 3.0 too.

To reproduce:

class Page extends SiteTree {

    private static $has_one = array(
        'TestFile' => 'File'
    );

    function getCMSFields() {
        $fields = parent::getCMSFields();
        $fields->addFieldToTab("Root.Main", new UploadField('TestFile', 'Test File'), "Content");
        return $fields;
    }
}

screen shot 2015-08-02 at 6 51 57 pm

@stevie-mayhew
Copy link
Contributor

I don't think this is a bug - images are files, but files are not images. You've defined that you want a file, and a file has been uploaded 😉

@jonom
Copy link
Contributor Author

jonom commented Aug 3, 2015

I realise that :) but in this case the file is an image so it should be detected and treated as such. If you upload an image through the Files interface it is recorded as an Image, so it should work the same way here.

@stevie-mayhew
Copy link
Contributor

Oh I see, so that its consistent. Makes sense in that case 😃

@jonom
Copy link
Contributor Author

jonom commented Aug 3, 2015

The interface even tells you it's an image:

screenshot_2_08_2015_7_43_pm

but if it's got a class of File you can't use any Image related functions in templates etc.

@stevie-mayhew
Copy link
Contributor

So is it that it should be loaded as an image, but then treated as a file in the relation? Adding an Image class which was uploaded through file admin shouldn't have the image methods on it (nor would I expect it to) but do they?

@sminnee
Copy link
Member

sminnee commented Aug 3, 2015

It was never a design goal to have objects of type File referencing image files, so I would think of this as a bug. If there are different behaviours between File .jgps and Image .jpgs (e.g. how they get inserted in the WYSIWYG editor) I would expect those differences to confuse the hell out of most users. ;-)

@jonom
Copy link
Contributor Author

jonom commented Aug 3, 2015

The problem here is that the Upload process and the Relationship setting should be two separate processes. The Upload should happen first, and if it's an image, an Image record should be added to the DB. Then the ID of the File (which just happens to be an Image) should be saved to the relation. The fact the we're saving in to a File relationship here shouldn't affect how an uploaded file is treated when it's added to the database.

@jonom
Copy link
Contributor Author

jonom commented Aug 3, 2015

Thanks @sminnee yes it definitely makes for a poor user experience ;) I'm surprised it hasn't been noticed before actually!

@jonom
Copy link
Contributor Author

jonom commented Aug 3, 2015

Weirdly, the image is still available to select for inserting in a HTMLEditorField, though thumbnails and Width and Height fields are missing. Once you've inserted an image though if you try to save the page you get a 500 error Uncaught Exception: Object->__call(): the method 'getwidth' does not exist on 'File'.

I thought for sure that GridField instance would only be showing Image objects as other files with ClassName=File are not shown... maybe it's doing some inefficient filtering on file extension or something? I'm sure something can be improved there and incidentally also note that the original file is displayed in the editing interface - that could be a 5mb download! In the Files section that image is a ScaleWidth(400) I believe.

silverstripe_-_edit_page

screen_shot_2015-08-02_at_8_40_31_pm

@lukereative
Copy link

Closing as I have tested and confirmed this is fixed in SS 4.x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants