Copied to clipboard

Flag this post as spam?

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


  • Matthew 14 posts 84 karma points
    Jul 01, 2018 @ 22:34
    Matthew
    0

    Umbraco7 contentservice delete contentitem

    Hi.

    I am using the content service to remove a content item -

               ApplicationContext
                    .Current
                    .Services
                    .ContentService
                    .Delete(contentItem);
    

    This works great. Node is removing from the database as expected. No problems. However, noticed some worrying behaviour. When this code is executed a folder (containing images) within .\media...\london.. is also magically removed. The node being removed is pretty standard, afew props - image, text fields and a textarea.

    Can anyone explain why that code is not just confined to the task at hand (removing the node from the cms) but also removing a file system folder? Been scratching my head, debugging, the folder goes at the point that delete method is called.

    Is there a safer / better way to perform a deletion of a node in umbraco7?

    Thanks

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Jul 02, 2018 @ 07:02
    Dave Woestenborghs
    0

    Hi Matthew,

    Is your Image property a upload of image cropper datype ? Then that could be the cause.

    Dave

  • Matthew 14 posts 84 karma points
    Jul 02, 2018 @ 11:55
    Matthew
    0

    Hi Dave, thanks for reply. The data type on this particular doc type is the standard file-upload (which displays a preview of the image). I worked on feature to be able to remove this doc type in code, but realised the parent folder of the image (which lives under ./media) was also vanishing - meaning all other images in that folder would go. Luckily this all local dev stuff - but really scratching my head to figure out how a very standard contentservice...delete(contentitem) is taking that image parent folder with it (off the file system) ....... any other thoughts?

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Jul 02, 2018 @ 12:49
    Dave Woestenborghs
    0

    Hi Matthew,

    I didn't check the source do but this is what I suspect why this is happening.

    When you use a file upload property the uploaded file is not available as an item in the umbraco media library. The file itself however is stored in the media folder.

    So when you delete a content item, is deleted the file is deleted as well because it can not be reused in Umbraco. Seems to m as expected behavior because otherwise it will leave your media folder with a lot of files that are not used anymore.

    Dave

  • Matthew 14 posts 84 karma points
    Jul 02, 2018 @ 22:35
    Matthew
    0

    Dave,

    Ok I see. Yes that would make sense. These are images but not media library items. I think there was a reason I needed to add the folder under ‘media’ (maybe to see the thumbnail in back office).

    2 options. I actually don’t need that file upload data type on the item. Can remove it and see how that goes. Even better still going forward - can try moving these up and out and into a different folder, away from media.

  • Matthew 14 posts 84 karma points
    Jul 03, 2018 @ 11:45
    Matthew
    0

    Hi Dave, If I try and move those images out the media folder they are not rendered in back office (in that file upload data type).

    Example - this path .... http://...../umbraco/backoffice/UmbracoApi/Images/GetBigThumbnail?originalImagePath=/images/folder/IMG_1234.JPG

    will return "ExceptionMessage": "File '/images/folder/IMG_1234.JPG' is outside this filesystem's root.", "ExceptionType": "Umbraco.Core.IO.FileSecurityException", "StackTrace": " at Umbraco.Core.IO.PhysicalFileSystem.GetFullPath(String path)\r\n at Umbraco.Core.IO.PhysicalFileSystem.GetLastModified(String path)\r\n at Umbraco.Web.Editors.ImagesController.GetResized(String imagePath, Int32 width, String sizeName) .........

    whereas http://...../umbraco/backoffice/UmbracoApi/Images/GetBigThumbnail?originalImagePath=/media/folder/IMG_1234.JPG

    returns the image fine.

    Before I start digging in to this stack trace / exception I thought you might know what this ? and if / how it is possible to enable folders to return images outside the media folder (config?).

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Jul 03, 2018 @ 13:07
    Dave Woestenborghs
    0

    Hi Matthew,

    Maybe a stupid question...but why you want to save your files in another location ?

    Is there any special requirement for that ?

    Dave

Please Sign in or register to post replies

Write your reply to:

Draft