Copied to clipboard

Flag this post as spam?

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


  • mathieu 1 post 71 karma points c-trib
    Oct 18, 2016 @ 15:42
    mathieu
    0

    Uploading Image as File

    Hey, i am currently trying to upload an image as a File Media type and i get this error... This code works well for files that arent images and when i upload an image as a Media Type Image it works fine.

    Error is "No PropertyType exists with the supplied alias: umbracoWidth" i get this at the result.SetValue line.

    IMedia result = Services.MediaService.CreateMedia(fileName, sharedContentNode.Id, importedData.ContentType.ToString());
                if (importedData.ContentType.ToString() == "Image" || importedData.ContentType.ToString() == "File")
                {
                    JArray j = new JArray(importedData.Properties);
                    var umbracoFile = j.First(x => x["Alias"].Value<string>() == "umbracoFile");
                    if (umbracoFile != null) {
                        string fileValue = umbracoFile["Value"].ToString();
                        if (!string.IsNullOrEmpty(fileValue)) {
                            mediaFullPath = "C:/PTC/medias/" + fileValue;
                            var file = new FileInfo(mediaFullPath);
                            using (var fs = file.OpenRead())
                            {
                                result.SetValue("umbracoFile", file.Name, fs);
                                Services.MediaService.Save(result);
                            }
                        }
                    }
                }
    

    Thanks for the help !

  • Sven Geusens 169 posts 881 karma points c-trib
    Oct 21, 2016 @ 13:53
    Sven Geusens
    0

    Hey Mathieu

    I have no idea why its throwing that error, but I find it strange that you are doing this Services.MediaService.CreateMedia(fileName, sharedContentNode.Id, importedData.ContentType.ToString()) when you want to save to a file type even if it's an image (if i understand your explenation correctly). Why not do Services.MediaService.CreateMedia(fileName, sharedContentNode.Id, "File")

  • Simon 692 posts 1068 karma points
    Apr 26, 2017 @ 09:02
    Simon
    0

    Hi Mathieu,

    How have you solved this issue, please?

    Thanks

    Kind Regards

  • Chris Mahoney 242 posts 454 karma points
    May 16, 2017 @ 20:52
    Chris Mahoney
    0

    Same problem here (Umbraco 7.5.12). I'm using the "File" media type but it's trying and failing to set umbracoWidth when the user uploads an image file.

    Did anyone figure this out?

    Edit: I've logged a bug.

Please Sign in or register to post replies

Write your reply to:

Draft