Jump to:

7940 Posts in 1543 Topics by 946 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » DOM and Uploadify image not attaching

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1 2 3 4
Go to End
Author Topic: 4990 Views
  • aarono
    Avatar
    Community Member
    34 Posts

    Re: DOM and Uploadify image not attaching Link to this post

    Hi UncleCheese,

    That doest seemed to have helped unfortunately. This is a truly confusing problem.

    Where is the refresh function so I can try debug inside there? I have looked inside FileUploadField and MultipleFileUploadField as both have a refresh() but if I try to print something to the browser, it doesnt show?

  • UncleCheese
    Avatar
    4085 Posts

    Re: DOM and Uploadify image not attaching Link to this post

    Look at line 42 or uploadify_init.js. It runs an ajax call to /YourFormField/refresh/:

                         $.ajax({
                            url: $e.metadata().refreshlink,
                            data: {'FileIDs' : ids.join(",")},
                            async: false,
                            dataType: "json",
                            success: function(data) {
                               $preview.html(data.html);
                            }
                         });

    Make sure that's running!

  • UncleCheese
    Avatar
    4085 Posts

    Re: DOM and Uploadify image not attaching Link to this post

    FYI, last time I saw this, the success function wasn't firing, despite the 200 response code. I eventually figured out that it had something to do with the content negotiator. It was bizarre.

    But to test it, you can put an error handler in..

    error : function(jqXHR, textStatus, errorThrown) {
    console.log(textStatus, errorThrown);

    }

  • aarono
    Avatar
    Community Member
    34 Posts

    Re: DOM and Uploadify image not attaching Link to this post

    Hmm, I put the error handler in, but it doesnt throw anything. Where exactly should I put it? I think I have it in the wrong place...

    I put this in the ajax call:

    success: function(data) {
    alert(data);
    $preview.html(data.html);
    }

    and data comes back as null... So it is definitely running the function, but it isn't responding with the files?

  • UncleCheese
    Avatar
    4085 Posts

    Re: DOM and Uploadify image not attaching Link to this post

    OK, that's actually a good thing because it probably means you can debug within PHP.

    Look at UploadifyField::refresh(). There may be different refresh() functions for each descendant of UploadifyField, so make sure you check those first. I believe FileUploadField and MultipleFileUploadField, for instance, have their own refresh() handlers.

    Find the right refresh() function and just start adding echo statements in the function, leaving your alert(data) statement in there. (console.log() is probably a better option for you, since it will show the contents of the returned object).

    Start by putting an echo statement at the first line of the function and work your way down until you figure out why the return is coming back null, and let me know the results!

  • aarono
    Avatar
    Community Member
    34 Posts

    Re: DOM and Uploadify image not attaching Link to this post

    Ok making progress here. I found the correct refresh function - its MultipleFileUploadField::refresh(). I put an echo right at the very start of the function, but i was still getting null returned. So I copied the URL from the request into the browser and still got null. See here:
    http://rocna.com/admin/EditForm/field/MediaImages/UploadifyForm/field/UploadedFiles/refresh?SecurityID=3751a3c35bcec9609407f090f86d285e97146dcc&ctf[MediaImages][start]=0&ctf[MediaImages][per_page]=10&ctf[MediaImages][showall]=0&ctf[MediaImages][sort]=SortOrder&ctf[MediaImages][sort_dir]=&ctf[MediaImages][search]=&ctf[MediaImages][filter]=&ctf[MediaImages][view]=grid&ctf[MediaImages][imagesize]=100&FileIDs=198

    However, if I remove all the request data and just browse directly the function, like so:
    http://rocna.com/admin/EditForm/field/MediaImages/UploadifyForm/field/UploadedFiles/refresh

    I get a response along these lines (you can see my echo 'hello' at the start)

    hello{"html":"
    Attached files<\/div>\n
    \n\t\n\t
    \n\t\t\n\t\t\tNo files attached\n\t\t\n\t<\/div>\n\t\n<\/div>\n\n
    \n\t\n<\/div>","success":"Added files successfully."}

  • aarono
    Avatar
    Community Member
    34 Posts

    Re: DOM and Uploadify image not attaching Link to this post

    Interesting.... now the url works, even with everything there...

    http://rocna.com/admin/EditForm/field/MediaImages/UploadifyForm/field/UploadedFiles/refresh?SecurityID=3751a3c35bcec9609407f090f86d285e97146dcc&ctf[MediaImages][start]=0&ctf[MediaImages][per_page]=10&ctf[MediaImages][showall]=0&ctf[MediaImages][sort]=SortOrder&ctf[MediaImages][sort_dir]=&ctf[MediaImages][search]=&ctf[MediaImages][filter]=&ctf[MediaImages][view]=grid&ctf[MediaImages][imagesize]=100&FileIDs=198

    But I havent changed anything since, so its intermittent??

    UPDATE: Ok so I see a relation to what is causing the problem. This url works:
    http://rocna.com/admin/EditForm/field/MediaImages/UploadifyForm/field/UploadedFiles/refresh?FileIDs=198
    This one doesnt:
    http://rocna.com/admin/EditForm/field/MediaImages/UploadifyForm/field/UploadedFiles/refresh?FileIDs=199

    The file ID 198 DOESNT exits in the File table in the database, but 199 does... However, I cant see why that would cause my echo to not be returned, when its right at the start of the function:

    public function refresh() {
          print_r('hello');
          ContentNegotiator::disable();
          $count = 0;
          $before = is_array($this->Value()) ? sizeof($this->Value()) : 0;
          if(isset($_REQUEST['FileIDs'])) {
             $ids = explode(",",$_REQUEST['FileIDs']);
             if(is_array($ids)) {
                $this->setValue($ids);
                $count = sizeof($ids) - $before;
             }
          }   
          return Convert::array2json(array(
             'html' => $this->renderWith('AttachedFiles'),
             'success' => sprintf(_t('Uploadify.SUCCESSFULADDMULTI','Added files successfully.'), $count)
          ));
       }

  • aarono
    Avatar
    Community Member
    34 Posts

    Re: DOM and Uploadify image not attaching Link to this post

    Still stuck on this.... Any ideas UC?

    4990 Views
Page: 1 2 3 4
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.