Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Nikolaj Dam Larsen 10 posts 30 karma points
    Aug 23, 2011 @ 18:14
    Nikolaj Dam Larsen
    0

    Using uploadify macro on a custom dashboard

    I'm trying to embed Gecko Uploadify on a custom dashboard by inserting the macro into a control like this:

    umbraco.presentation.templateControls.Macro mcr = new umbraco.presentation.templateControls.Macro();
    mcr.Alias = "GeckoUploadify";
    mcr.MacroAttributes.Add("MediaFolder", imageUploadProperty);
    mcr.MacroAttributes.Add("AllowedTypes", "*.jpg|*.png|.gif");
    imageUploadProperty.Controls.Add(mcr);

    The Uploadify flash content and everything else seems to be embedded correctly, and I'm able to browse files and start the upload. But whenever I've selected the files to be uploaded i get a messagebox saying "An error occurred: No node exists with id '0'". The point where this error happens, is before the first file is uploaded, but after the file size is checked, as i still get the "File Size Error" for files above the Web.config max.

    The uploader works just fine when used in the Media section as a property in the Folder type, so its not an installation option.

    Is there something I'm missing when adding the macro like this? I'd probably be looking into the source code for this answer if it were available, but as this is not the case, I sincerely hope some of you may help. 

    Thanks in advance.

    - Nikolaj

  • Emanuel 63 posts 283 karma points
    Aug 23, 2011 @ 19:29
    Emanuel
    0

    Hi,

    I think you have a problem with the target media folder.
    Can you test an upload in Firefox and check what gets sent to "Uploadify.ashx" when uploading? There should be a "mediaFolder" parameter in there, what's the value?

  • Nikolaj Dam Larsen 10 posts 30 karma points
    Aug 23, 2011 @ 20:00
    Nikolaj Dam Larsen
    0

    I'm not sure if this is what you mean, but here is some of the jQuery script concerning the .ashx file and a mediaFolder parameter:

    input.uploadify({
      'uploader': '/usercontrols/Gecko.Uploadify/uploadify.swf',
      'script': '/usercontrols/Gecko.Uploadify/Uploadify.ashx',
      'cancelImg': '/usercontrols/Gecko.Uploadify/cancel.png',
      'auto': true,
      'multi': true,
      'wmode': 'transparent',
    //'buttonImg' : '/usercontrols/Gecko.Uploadify/upload.png',
    //'width': 102,
    //'height': 37,
      'sizeLimit': 4194304,
      'buttonText': 'Upload Files',
      'scriptData': {
        'AUTHID': auth,
        'mediaFolder' : 0
      }
      ,'onComplete': function(event, queueID, fileObj, response, data) {
        if (response != "1") { 
    errorsOccurred = true; alert(response); 
    } return false; } ,'onAllComplete': function(event, data) { if (data.errors == 0 && !errorsOccurred) { window.location.reload(); } errorsOccurred = false; }
    });

     

    The value of mediaFolder seems to be 0, which is in accordance to the error message. I'm pretty sure, though, that I'm adding the right node id to the macro using "mcr.MacroAttributes.Add("MediaFolder", imageBrowserMediaNodeId);" as i check the validity of the id before i add the macro to the property control. Is there some other way to add this mediaFolder id?

  • Emanuel 63 posts 283 karma points
    Aug 23, 2011 @ 21:18
    Emanuel
    0

    The Uploadify.ascx usercontrol has a public int MediaFolder { get; set; } that is rendered directly on the page.

    The fact that you're seeing a "mediaFolder: 0" means somehow the binding isn't happening, i.e., the MediaFolder property is 0.

    Perhaps you're not calling the MacroAttributed.Add method in the right time, try changing it to Init, Load, PreRender...

     

  • Nikolaj Dam Larsen 10 posts 30 karma points
    Aug 23, 2011 @ 22:24
    Nikolaj Dam Larsen
    0

    I made it work now after having a look at the Macro class in the Umbraco source.

    I changed

    mcr.MacroAttributes.Add("MediaFolder", imageBrowserMediaNodeId);

    to

    mcr.Attributes.Add("MediaFolder", imageBrowserMediaNodeId.ToString());

    This works because items in the Attributes hashtable is added to the MacroAttributes before the Control is rendered.
    Why it didn't work with the MacroAttributes table, I don't know, but my guess is its due to incorrect typecasting of the value object.
    I might try and do a ToString() on the value added to MacroAttributes, just to see if that would have solve my trouble.

    But thank you Emanuel for pointing me in the right direction and for a great uploadify package.

    - NIkolaj 

     

    Edit: It didn't work with adding ToString and use the MacroAttributes hashtable, but the first solution still works, so Attributes is the way to go.

Please Sign in or register to post replies

Write your reply to:

Draft