On Sat, Mar 12, 2011 at 2:38 PM, Foroct <[email protected]> wrote:
> I kicked this around for a few days and I still cant make it work.
>
> My model is "Recipe" and it is using the plugin
> var $actsAs = array('Media.Transfer', 'Media.Generator',
> 'Media.Coupler');
> When I upload using a form everything is perfect.
>
> From my app, I'm sending the photo (via XHR) to this controller
>
> function app_photo() {
>                // what layout to use
>                $this->layout = 'ajax';
>
>                // this helps determine any errors
>                error_reporting(E_ALL);
>                ini_set("display_errors", 1);
>
>                $this->data['media']; // what is getting passed
>
>                $file = $this->Recipe->transfer($this->data['media']); // 
> handle
> upload
>                $this->Recipe->make($file); // generate versions
>
>                $fileName = $this->Recipe->transferred();       // create var 
> for the
> transferred item
>                        // then return the name
>                        echo $fileName;
>
>                }
>
>        }
>
> Now I'm not even getting my file saved initially so no versions are
> being generated and it returns nothing to my app.
>
> I'm at a total loss of what to do.

There's no support for file uploads via XHR. To mimic it, though, you
can create a hidden iframe and set the form's target to the iframe id.
The server will send the response to the iframe. Here's a basic recipe
using JQuery.

$('#submit_button_id').click(function(event)
{
        event.preventDefault();
        
        /* form response will be sent to the iframe
         */
        $('#iframe_id').bind('load', function()
        {
                /* grab the HTML from the view that was rendered
                 */
                var response = $(this).contents().find('body').html();
                
                if (response.length)
                {
                        // deal with response, clean up, etc.
                }
                else
                {
                        /* this should do something a bit more sophisticated.
                         */
                        alert('upload failed');
                }
        });
        
        /* submit the form and perhaps fade it out, show a 'loading' gif, etc.
         */
        $(this).parents('form').submit();
});

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to