Copied to clipboard

Flag this post as spam?

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


  • Matthias 87 posts 173 karma points
    Oct 22, 2012 @ 11:44
    Matthias
    0

    Media.AfterSave and FileSystemProviders

    Hi,

    i've update a website from 4.5.2 to 4.9 and am now struggling with the new FileSystemProviders concept.

    In the old version i hooked up to the Media.AfterSave event to allow the editor to optionally upload files to the folder "uploads" (which resides physically on the same level as the "media" folder). This is based on the media type that is chosen:

    void Media_AfterSave(Media sender, umbraco.cms.businesslogic.SaveEventArgs e) {
    if (sender.ContentType.Alias == "UploadFile") {
    Property fileprop = sender.getProperty("umbracoFile");
    Property extensionprop = sender.getProperty("umbracoExtension");

    if (!string.IsNullOrEmpty(fileprop.Value.ToString())) {
    //get its path
    string path = fileprop.Value.ToString();

    //does it use the standard path?
    if (path.Contains("/" + fileprop.Id.ToString() + "/")) {
    string newDirectory = "/uploads/";
    string newPath = newDirectory + sender.Text + "." + extensionprop.Value.ToString();

    //copy the old file to the new location
    System.IO.File.Copy(HttpContext.Current.Server.MapPath(fileprop.Value.ToString()), HttpContext.Current.Server.MapPath(newPath), true);

    //delete the old file
    System.IO.File.Delete(HttpContext.Current.Server.MapPath(fileprop.Value.ToString()));

    //set the file property to the new friendly path
    fileprop.Value = newPath;
    }
    }
    }
    }


    The upload still works, but the path to the file in the Media section in Umbraco always gets prefixed with "/media/" (e.g. "/media/uploads/example.pdf" instead of "/uploads/example.pdf").

    I guess it's caused by the "virtualRoot" parameter in the FileSystemProviders.config

    How can i achieve a correct path in the Media section?

    Thanks!
    Matthias

  • Matthias 87 posts 173 karma points
    Oct 24, 2012 @ 20:39
    Matthias
    0

    ...ended up in injecting some jQuery in editmedia.aspx to adjust the filepath. Fast and easy solution. Thanks to Lee Kelleher for inspiration and code snippet on github.

  • Jordi Bartolomé 21 posts 41 karma points
    Jan 07, 2013 @ 14:41
    Jordi Bartolomé
    0

    How can I do that if the new folder is not in the same server? 

    e.g.: server in which I have umbraco: http://www.myserver.com

    server in which I wanna store all media: http://static.myserver.com

     

    how can I  do that?

     

    thanks!

Please Sign in or register to post replies

Write your reply to:

Draft