Copied to clipboard

Flag this post as spam?

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


  • sperr0w 48 posts 81 karma points
    Dec 26, 2009 @ 18:16
    sperr0w
    0

    add media items programmaticaly

    Hi!

    I have an image for example c:\Image1.jpg.

    I need to upload this image to umbraco media folder programmaticaly.

    P.S. I make migration of one site to umbraco. and I have directory of images, that I need to upload in media. I know about ZipUpload pack? but I need to do some additional actions when I upload files, that's why I can use ready pack.

    Can u give me the pogram code of how to upload single file to media folder and create media item in umbraco.

    i know how to create media item usint Media.MakeNew, but I dont know, how to move file to Media\{someId}\filename. What is this folder {someId}? Can u give full code.

  • sperr0w 48 posts 81 karma points
    Dec 26, 2009 @ 18:19
    sperr0w
    0

    I tried to analize zipUpload pack, but I have no any results. May be creator of this pack give me the code for single jpg file, not for archive of files.

  • sperr0w 48 posts 81 karma points
    Dec 26, 2009 @ 18:28
    sperr0w
    0

    after I move all images to media, I plain to add media items using UI. So I need to genereate media as umbraco make it ( to avoid conflicts).

  • mfeola 117 posts 221 karma points
    Oct 04, 2010 @ 20:32
    mfeola
    0

    I am actually working on this myself.  If I find a way to do it I will post it here.

  • Ernst Utvik 123 posts 235 karma points
    Oct 08, 2010 @ 01:30
    Ernst Utvik
    0

    Hope the posted code will get you on your way. Let us know how your doing :)

    // Adds to media section in umbraco
                    string fileId = doc.getProperty("imageAlias").Id.ToString();
                    string directory = Server.MapPath(string.Format("/media/" + fileId + "/"));
    string filef = fileUpload.FileName;
    var ext = filef.Substring(filef.LastIndexOf(".") + 1, filef.Length - filef.LastIndexOf(".") - 1).ToLower();
    var fileNameWOExt = filef.Substring(0, filef.Length - (ext.Length + 1));
    string _fullFilePath = directory + filename;
                    //Adds a thumb for viewing in umbraco
    string fileNameThumb = _fullFilePath.Replace("." + ext, "_thumb");
    thumbBMP.Save(directory + fileNameWOExt + "_thumb.jpg");

    System.IO.FileInfo fi = new FileInfo(_fullFilePath);

    Media m = null;
    m = Media.MakeNew(
    fileNameWOExt, MediaType.GetByAlias("image"), User.GetUser(0), 1377); //last property is the id of parent folder
    string mediaPath = "/media/" + fileId + "/" + fileUpload.FileName;
    m.getProperty("umbracoWidth").Value = newWidth.ToString();
    m.getProperty("umbracoHeight").Value = newHeight.ToString();
    m.getProperty("umbracoFile").Value = mediaPath;
    m.getProperty("umbracoExtension").Value = ext;
    m.getProperty("umbracoBytes").Value = fi.Length.ToString();
  • Anton 135 posts 186 karma points
    Feb 15, 2012 @ 09:47
    Anton
    0

    I have  error CS0103: The name 'thumbBMP' does not exist in the current context

  • Anton 135 posts 186 karma points
    Feb 15, 2012 @ 10:01
    Anton
    0

    I have thumb image how I can add it to current Image?

  • mfeola 117 posts 221 karma points
    Feb 15, 2012 @ 16:40
    mfeola
    0

    thumbBMP doesn't get used in the function does it? take it out and see what happens

  • Anton 135 posts 186 karma points
    Feb 15, 2012 @ 22:18
    Anton
    0

    this is my code  

    Media m= Media.MakeNew("99", MediaType.GetByAlias("image"), author, 1072); 

    m.getProperty("umbracoFile").Value = "http://localhost:31235/media/6014/"+"0_big"+".jpg";

      How I can add thumb for this image? I create 0_big_thumb.jpg near 0_big.jpg, but I dont see thumb on umbraco. Maybe I need to registrate thumb image, but how?

Please Sign in or register to post replies

Write your reply to:

Draft