Copied to clipboard

Flag this post as spam?

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


  • Mahender Singh 39 posts 170 karma points
    Jun 19, 2022 @ 17:13
    Mahender Singh
    0

    Added Image Media via code not showing in Umbraco Admin panel

    Hi Team,

    I have added Images in Umbraco Media using the code. Folder and Subfolder are created successfully and Images also...but Images are not showing in Admin panel.

    Below is the code which i am using...help me if i am doing something wrong.

    IMedia? _userProfilefolder = _mediaService.GetRootMedia().FirstOrDefault(m => m.Name.InvariantEquals("UserProfile"));
                if (_userProfilefolder == null)
                {
                    _userProfilefolder = _mediaService.CreateMediaWithIdentity("UserProfile", Constants.System.Root, MediaTypes.Folder);
                }
                IMedia? usernameFolder = _mediaService.GetPagedChildren(_userProfilefolder.Id, 0, int.MaxValue, out var folderCount)
                                         .Where(x => x.ContentType.Alias == Constants.Conventions.MediaTypes.Folder)
                                          .FirstOrDefault(c => c.Name.InvariantEquals(username));
                if (usernameFolder == null)
                {
                    usernameFolder = _mediaService.CreateMediaWithIdentity(username, _userProfilefolder.Id, MediaTypes.Folder);
                }
                await using (var ms = new MemoryStream())
                {
                    await file.CopyToAsync(ms);
    
                    var media = _mediaService.CreateMedia("ProfilePic2.jpg", usernameFolder.Id, Constants.Conventions.MediaTypes.Image);
    
                    media.SetValue(_mediaFileManager, _mediaUrlGenerators, _shortStringHelper, _contentTypeBaseServiceProvider, Constants.Conventions.Media.File, "ProfilePic2.jpg", ms);
    
                    _mediaService.Save(media);
                }
    

    enter image description here

  • Mahender Singh 39 posts 170 karma points
    Jun 21, 2022 @ 04:44
    Mahender Singh
    0

    Hi Team,

    Just to update everything is fine...but issue is that...I am storing the Media using the API, which is another application not the CMS application it self.

    So i just want to know...how to setup the application URL and Media path in api application for CMS application.

Please Sign in or register to post replies

Write your reply to:

Draft