Copied to clipboard

Flag this post as spam?

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


  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Jul 22, 2010 @ 15:07
    Jeroen Breuer
    0

    Hello,

    I've got the following situation. After uploading an image with uploadify I want to get the image and resize it in different formats. I thought I could use the Media.New event for this, but if this event is called no image is set yet (umbracoFile is empty). This is probably done after the media file is created. Is there some way (like a different event) I can still get the image to resize it?

    Jeroen

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Jul 22, 2010 @ 15:11
    Jeroen Breuer
    0

    Ok already got it. The Media.AfterSave also get's called and in this event the image is available :).

  • Ismail Mayat 4511 posts 10090 karma points MVP 2x admin c-trib
    Jul 22, 2010 @ 15:15
    Ismail Mayat
    0

    Jeroen,

    What version of umbraco?  I tried AfterSave with 4.0.3 and still didnt get a file so i had to do:

     

    mediaItem m = getMediaData(id);
    
    //update the doc xml
    node = addMediaInfoToXmlDoc(m, node);
    
    
    /// <summary>
    /// add the missing info to xml doc so that we can index the media item
    /// </summary>
    /// <param name="m"></param>
    /// <param name="n"></param>
    /// <returns></returns>
    private XmlNode addMediaInfoToXmlDoc(mediaItem m, XmlNode n){
        XmlNode node = n;
        n.SelectSingleNode("/node/data[@alias='umbracoFile']").InnerText = m.url;
        n.SelectSingleNode("/node/data[@alias='umbracoExtension']").InnerText = m.ext;
        return node;
    }
    
    /// <summary>
    /// have to do this becuase we dont have it in the xml
    /// something todo with order of events, ie item is saved but file path and extension is not picked up at this point
    /// </summary>
    /// <param name="mediaId"></param>
    /// <returns></returns>
    private mediaItem getMediaData(int mediaId) {
    
    
        string sql = "select dataNvarchar from cmsPropertyData where contentnodeid=@id and (propertytypeid=24 or propertytypeid=25)";
        mediaItem md = new mediaItem();
        StringBuilder sb=new StringBuilder();
    
        IRecordsReader dr = SqlHelper.ExecuteReader(sql, SqlHelper.CreateParameter("@id", mediaId));
    
        using (dr)
        {
    
            while (dr.Read())
            {
                sb.Append(dr.GetString("dataNvarchar"));
                sb.Append(",");
    
            }
    
        }
    
        string result = sb.ToString().TrimEnd(new char[] { ',' });
        string[] res = result.Split(new char[] { ',' });
        md.url = res[0];
        md.ext = res[1];
    
        return md;
    }
    
    
    #endregion    
    
    public static ISqlHelper SqlHelper
    {
        get
        {
    
            return Application.SqlHelper;
    
        }
    }
    
    
    Regards
    Ismail
  • Emanuel 63 posts 283 karma points
    Jul 22, 2010 @ 15:17
    Emanuel
    0

    Hi Jeroen,

    There is in fact an event you can subscribe to in order to make any further processing on the image.
    The Uploadify class has a static FileUploaded event that you can use.
    The FileUploadedEventArgs  argument to the  subscribed methods will contain an UploadifySettings object with the following properties:

    int MediaFolderId - the destination folder for the file
    User UploaderUser - the user uploading the file, if exists
    Member UploaderMember - the member uploading the file from the front-end, if exists
    HttpPostedFile File - the file
    bool Cancelled - if you set this flag to TRUE, the upload event will be cancelled
    string CancelledMessage - if the event is cancelled, this message will be displayed to the user

    Let me know if you need further help, or if something doesn't work.

    Cheers,

    Emanuel

     

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Jul 22, 2010 @ 15:34
    Jeroen Breuer
    0

    @Ismail I'm Using Umbraco 4.5 so that must be difference.

    @Emanuel Thanks for the info. Since the Media.AfterSave works for me I'll just use that.

    Jeroen

Please Sign in or register to post replies

Write your reply to:

Draft