Me, Myself and Drupal – Chapter 6: Image uploads, Comment Attachments

Jul 1st, 2010 | By | Category: Technology

If you were thinking that the Drupal excitement was going to let up as we progressed then you are definitely in for a treat because it’s still as troublesome wrangling this CMS to do exactly what I want it to as before.

Because I’ve spent the past 2-3 years working with Dotproject I’ve come to expect certain features in a PMS.  For example, I want my crew to be able to attach WIP’s if they are commenting on a task that they are working on.  This way the conversation can be contained all within the PMS and you dont’ need a second system to talk about the task that you are working on.  Well Drupal doesn’t do this.  The thing with Drupal is that you can only attach images, or files in general to things that create nodes.  Image nodes, pages, books, etc etc.  Well with Storm the way that you update your task is by filing out a Time Tracking sheet or by commenting on it.  The problem is that comments don’t create nodes unto themselves they are tacked onto existing nodes, meaning that uploads and attachments aren’t allowed.  Funny enough the same goes for the Forums.  In an oversight that is almost embarassing the Drupal forums don’t allow you to attach files or images to any replies to an original post, something which all forums have been doing since the dawn of time.   There is however a nice comment attachment module that you can install, although that wasn’t without it’s challenges.

Firstly, for whatever reason the comment attachment module figures that it needs to stick the files in /system/files/images or /system/files .  The problem here of course is that this directory doesn’t exist.  IT is not part of the drupal install at all, no other module creates or needs it, but for some reason the comment attachment module figures this is where files go, when in fact they are being uploaded to /sites/{yoursitename}/files or /sites/default/sites as is specified by drupal.  So I could have gone through the module files and found where the hell the reference to this phantom dir was but instead I just hopped into my server and made a sym link to it.

# cd domain.com/drupal

#mkdir system

#cd system

#ln -s ../sites/{mysitename}/ ./

and viola, all of a sudden the comment uploader module had somewhere to throw it’s files and they all ended up in the same place as the other upload modules in drupal.

So this solved this problem, the module is actually almost 1/2 working now, key word ‘almost’ .  You first need to go into content types and find all of the content types that you want to enable the file uploads for the comments.   The forum is one obvious one, but I just went to every content type that is used frequently.  Posts, books, tasks, etc etc.  You have to configure each one, go down to the comments section and enable file attachments or uploads or whatever it is called.  And Viola!  You should have comment uploads… Key word here is ‘should’ because of course you still don’t.

The attach option now shows up on the comments, and sure enough you can click on the browse button and open a window to find the file that you want to upload, and sure enough you can start the upload process but right when it finishes you will see a beautiful error message saying “html error 0: /comment-upload/js”  .  Awesome eh?  Yea, I thought so too!  So now we figure out what the hell is causing this problem and it turns out that an asshole of a javascript is doing it because if you have NoScript installed in Firefox and you set this page and completely untrusted guess what you can do?  That’s right boys and girls you can upload and attach to your hearts content, which means that some jackass javascript is being a jerk.  Time to find out which one it is!

Now on my page I had the following scripts loading:

<script type="text/javascript" src="/misc/jquery.js?S"></script>
<script type="text/javascript" src="/misc/drupal.js?S"></script>
<script type="text/javascript" defer="defer" src="/modules/admin_menu/admin_menu.js?S"></script>
<script type="text/javascript" src="/modules/insertFrame/insertFrame.js?S"></script>
<script type="text/javascript" src="/modules/rounded_corners/jquery.corner.js?S"></script>
<script type="text/javascript" src="/modules/storm/storm.js?S"></script>
<script type="text/javascript" src="/modules/storm/storminvoice/storminvoice.js?S"></script>
<script type="text/javascript" src="/modules/storm/stormperson/stormperson.js?S"></script>
<script type="text/javascript" src="/modules/storm/stormproject/stormproject.js?S"></script>
<script type="text/javascript" src="/modules/storm/stormtask/stormtask.js?S"></script>
<script type="text/javascript" src="/modules/storm/stormticket/stormticket.js?S"></script>
<script type="text/javascript" src="/modules/storm_dashboard/json2.js?S"></script>
<script type="text/javascript" src="/modules/storm_dashboard/storm_dashboard.js?S"></script>
<script type="text/javascript" src="/misc/collapse.js?S"></script>
<script type="text/javascript" src="/modules/storm_quicktt/storm_quicktt.js?S"></script>
<script type="text/javascript" src="/modules/storm_quicktt/jquery.timers.js?S"></script>
<script type="text/javascript" src="/modules/tableofcontents/jquery.scrollTo-min.js?S"></script>
<script type="text/javascript" src="/modules/tableofcontents/jquery.localscroll-min.js?S"></script>
<script type="text/javascript" src="/modules/tableofcontents/tableofcontents.js?S"></script>
<script type="text/javascript" src="/modules/webfm/modules/webfm_mp3/mp3player/audio-player.js?S"></script>
<script type="text/javascript" src="/modules/fckeditor/fckeditor.utils.js?S"></script>
<script type="text/javascript" src="/misc/textarea.js?S"></script>

Now considering that basically everyone and their brother’s dog is bitching about Jquery fucking up everything it touches I tried renaming /misc/jquery.js to /misc/jquery.js.bak and you’ll never guess what happened next?  My image attachment/uploader module works.  I figured that some jquery is better than none, so I went over to http://docs.jquery.com/Downloading_jQuery , grabbed all of the older versions and started trying each one to see how far back I would have to go to get one that worked.  I simply download them all into my /misc/ directory and renamed them from jquery-1.4.js to jquery.js or whatever the version number was.  I had to go all the way back to version 1.2 before it stopped giving me that lovely error message.  I lost my fancy uploading progress bar but at least it works.

So ya, that has been my fun for today, I now have a fully function forum and PMS in the sense that I am used to.  Scratch those from the list! 🙂  Now I dive into the wide world of the SVN.  I feel this is going to be the most demanding, and most rewarding setup so far as a well setup SVN involves a fair bit of learning and understanding.  And if I can’t do it well then why bother at all so off I go to learn!

Tags: , , , , , , , ,

3 Comments to “Me, Myself and Drupal – Chapter 6: Image uploads, Comment Attachments”

  1. loR says:

    Hi,

    It doesn’t work for me (version 1.2 of Jquery).
    The problem isn’t in Safari but Firefox.
    The only issue I find than helps me is disable jquery.form.js in drupalsite/misc.
    It’s ugly but it works…

    However, thx for your post.

  2. admin says:

    Heh, indeed, I did write a little PS at the end of the article touching on that.. Try upgrading to the latest version of jquery.forms.js or ya, the other option is just to take it out all together.
    Messy for sure, but worth it I suppose

  3. Stephe says:

    This upload issue has been driving me CRAZY! I now mysteriously have it on 2 production sites and 1 in development. Seems to be contagious or something. I set up a test site specifically for this issue. Got the error. Joy. Renaming jquery.js.bak worked for the test site. Using 1.2 did not. Nor did using jquery.js from a working site. Or jquery.form.js or ahah.js from a working site. Disabling jquery isn’t really an option in the long term though, or an option for the production sites. The development site only worked once ahah.js was renamed .bak.

    I’m rambling from spending soooo many hours hunting around for this bizarre, inconsistent and always triggered problem…

    Thank you, thank you, thank you for posting something that can finally point me in the right direction for a legitimate fix for this for our sites!

Leave a Comment