Google Groups Home
Help | Sign in
Message from discussion Upload behavior
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
Tijs Teulings  
View profile
 More options Jul 13 2007, 4:20 am
From: Tijs Teulings <tteuli...@gmail.com>
Date: Fri, 13 Jul 2007 10:20:54 +0200
Local: Fri, Jul 13 2007 4:20 am
Subject: Re: Upload behavior
On 13-jul-2007, at 9:12, AD7six wrote:

> On Jul 12, 1:53 pm, Tijs Teulings <tteuli...@gmail.com> wrote:

> Hi Tarique,

> The behavior in cheesecake is almost stripped to the bone, and has
> some assumptions built in (where the files will go meaning the use of
> WWW_ROOT, each file is a foto, the format for the name of the thumb
> file etc.). For a photo driven site I guess it's what's needed.

> Hi Tijs,

> The paste was not for a finished version but I did a bit more than
> change the way the default setup works. I added/did the following:
>  * style changed to be more inline with other behaviors (use of
> extract so you don't need $this->params to refer to all your variables
> for example)
>  * changed to work with almost no parameters
>  * made separate methods for some operations such as determining file,
> thumb and path names
>  * the folder to save can be configured/changed on the fly 'dir' =>
> '{APP}uploads{DS}{$class}{DS}{$foreign_id}' <- those get replaced when
> used
>  * the thumb/versions to save can be configured/changed on the fly
> ''name' => '{$file}.small.{$ext}' <- can be what you like
>  * added a name cleanup routine (only applicable if you are not using
> random filenames) so that áccëñtèd characters in file names are
> converted
>  * fixed the beforeDelete method and wrote it to ensure that the pics/
> thumbs/versions of abcd.jpg are not deleted when you delete the pic
> bcd.jpg

> I changed it to use relative file paths when saving to the database,
> although that's currently hard coded. Not sure if it is still a bit
> too db-centric as a model may not be a table in the db of course.

> The thing that mildly bugged me before was that a file (upload) is a
> file, not a jpeg/png. The behavior was and still is (because I decided
> to stop thinking and just write something) a bit foto centric imo. I
> need to be able to upload images and pdfs, but the same upload
> behaviour could be used for any file type, so if it includes image
> resizing, shouldn't it include any of doc to text, text to pdf, mp3 to
> first x seconds, movie to first x seconds, unzip zip etc. ?

> I like the way cheesecake keeps things separate by outsourcing image
> manipulation to a vendor. Maybe configuring a callback is a
> possibility, maybe image resizing should be done in the model or maybe
> I'm thinking too much.

> Anyway, thoughts?

> AD

Hi Andy,

Ok, i missed all that from my quick scan of the code. Sounds  
excellent. What i'll do first is use your version as a base and then  
fix some of the things i found like the resizing and not being able  
to update 'extra' fields you might have used without uploading a new  
image.

I guess the second step would indeed be to generalize everything a  
bit more for file uploads of different types. I could take a look at  
the cheesecake method for 'outsourcing' image handling to a vendor.  
Some way to configure actions based on mimetype arrays would be  
nice... The filename array could serve as a base for that, i do like  
that you can set that up in the single model and don't need much  
logic in the controller at all. Something like this might work:

var $actsAs = array('Upload' => array(
                        'filename' => array(
                                'Image'=> array( // <-- file subtypes (may or may not refer to  
model)
                                        'dir' => 'files/images',
                                        'overwrite_existing' => false,
                                        'create_directory' => false,
                                        'allowed_mime' => array('image/jpeg', 'image/pjpeg', 'image/
gif', 'image/png'),
                                        'allowed_ext' => array('.jpg', '.jpeg', '.png', '.gif'),
                                        'thumbsizes' => array(
                                                                        'small' =>   array('width'=>100, 'height'=>100),
                                                                        'medium'=>   array('width'=>220, 'height'=>220),
                                                                        'large' =>   array('width'=>800, 'height'=>600)
                                        )
                                )
                                'Document'=> array(
                                        'dir' => 'files/docs',
                                        'overwrite_existing' => false,
                                        'create_directory' => false,
                                        'allowed_mime' => array('text/plain', 'application/msword',  
'application/pdf'),
                                        'allowed_ext' => array('.txt', '.pdf', '.doc'),
                                        'parse_text' => array(true, 'db_field'=>'text'), // parse text  
and store in db field for searches/extract
                                        )
                                )
                        )
                )
);

If you keep the handlers reasonably generic you could switch out  
vendors for each task with relative ease. This could get out of hand  
easily too though ;) You think each fieldtype should be handled by  
it's own model or should they just be methods of the File/Upload model?

Tijs


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google