Copied to clipboard

Flag this post as spam?

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


  • Bjørn Nyborg 9 posts 79 karma points
    Mar 30, 2016 @ 18:10
    Bjørn Nyborg
    0

    Some media are protected, others are not

    Hello!

    I have installed media protect on an Umbraco version 7.2.8 assembly: 1.0.5675.2346 today. Install went just fine, and i also manually checked the install afterwards, and looked through your documentation and everything seems just fine.

    Now i have protected a media folder (Rolebased), but not all medias in the folder is protected.

    On my project i have a member setup where the members can upload files, and none of the files uploaded through the frontend is protected (but they do have the "public access disabled" icon in the backend, see screenshot)

    I have also uploaded 2 files via. the backend, ("Ting" and "asdasd" from the screenshot). "Ting" which is a pdf file is protected just fine, but "asdasd" which is a jpg is NOT protected.

    I have enabled debug-mode to get some more info, and it looks like this:

    This is the entry for "Ting"

    <file dateTime="30-03-2016 19:49:22" path="/media/1030/invoice.pdf" isMedia="True" isProtected="True" hasAccess="False" redirectPage="/app/" nodeId="2271" user="[email protected]" />
    

    But then "asdasd" which is in the same protected folder looks like this:

    <file dateTime="30-03-2016 19:56:08" path="/media/1029/bg.jpg" isMedia="True" isProtected="False" hasAccess="True" redirectPage="" nodeId="0" user="[email protected]" />
    

    What can be the problem here? I just want everything in the protected folder to be protected according to the permissions set on the folder.

  • Amalie Wowern 144 posts 273 karma points MVP c-trib
    May 04, 2016 @ 08:45
    Amalie Wowern
    0

    Have same issue in same version of umbraco.

    And media protect 1.6.2

  • Bjørn Nyborg 9 posts 79 karma points
    May 04, 2016 @ 10:13
    Bjørn Nyborg
    0

    I changed "protectCropperImages" to true in the mediaprotect.config, and that solved the issue with the jpg.

    But i still have pdf files in the same protected folder where some is protected (ex. http://firmamappen.dk/media/1030/invoice.pdf)

    and some arent (ex. http://firmamappen.dk/media/11459345683790332243.pdf http://firmamappen.dk/media/41462356631209392243.png)

  • Vold Hooker 15 posts 35 karma points
    May 11, 2016 @ 05:39
    Vold Hooker
    0

    I am also having this issue.

    The problem might be that the mediaccess.config node ID does not match the node ID the protection code looks at.

    Entry in mediaaccess.config:

    <mediaAccess>
      <node id="6573" protected="True" simpleProtection="False" loginPage="1727" noRightsPage="1093" roles="SamsonMember" />
      <node id="6575" protected="True" simpleProtection="False" loginPage="1203" noRightsPage="1276" roles="SamsonMember" />
      <node id="6576" protected="True" simpleProtection="False" loginPage="1727" noRightsPage="1976" roles="SamsonMember" />
      <node id="6577" protected="True" simpleProtection="False" loginPage="1726" noRightsPage="1976" roles="SamsonMember" />
      <node id="6578" protected="True" simpleProtection="False" loginPage="1727" noRightsPage="1846" roles="SamsonMember" />
      <node id="6579" protected="True" simpleProtection="False" loginPage="1976" noRightsPage="1727" roles="SamsonMember" />
      <node id="6580" protected="True" simpleProtection="False" loginPage="1976" noRightsPage="1726" roles="SamsonMember" />
    </mediaAccess>
    

    Entry in mediaprotectdebuglog

      <file dateTime="11-05-2016 07:32:16" path="/media/1755/swoop.jpg" isMedia="True" isProtected="False" hasAccess="True" redirectPage="" nodeId="4995" user="" />
    

    On the one that works, it has the correct ID:

    <file dateTime="11/05/2016 07:35:35" path="/media/1750/jb-003.png" isMedia="True" isProtected="True" hasAccess="False" redirectPage="/about-us/" nodeId="6575" user="[email protected]" />
    

    Umbraco 7.2.8, media protect 1.6.2.

    Protects some files and not others. There's nothing consistent about it - I've used the same file and in one case it is protected, in two other cases it is not.

    I've got a customer who's getting a little impatient and would really appreciate some help.

  • Richard Soeteman 4045 posts 12898 karma points MVP 2x
    Jul 04, 2016 @ 07:25
    Richard Soeteman
    0

    Hi Bjorn,

    First of all completely missed this post. Sorry about that :-( In future please use [email protected] for urgent issues.

    If you protect the folder then all files are protected and with the current version of Umbraco you need to set protectcropedimages indeed.

    Can you check if mediaprotect.mvc.dll exists in the /bin folder, if it's not there can you add it manually and if it is there can you add the following line to web.config and see if it works now?

    <add key="MediaProtect.UseSeparateAppdomain" value="true" /> 
    

    Hope this helps,

    Richard

  • Bjørn Nyborg 9 posts 79 karma points
    Jul 04, 2016 @ 08:48
    Bjørn Nyborg
    0

    I do have the file in the /bin : http://prnt.sc/bojw10

    I think you forgot to add the web.config line i should insert. :)

  • Richard Soeteman 4045 posts 12898 karma points MVP 2x
    Jul 04, 2016 @ 08:50
    Richard Soeteman
    0

    Ok,

    Sorry line was added but nor marked as code. Updated now.

    Best,

    Richard

  • Bjørn Nyborg 9 posts 79 karma points
    Jul 04, 2016 @ 08:58
    Bjørn Nyborg
    0

    I added this is the appSettings section in the web.config, still no difference.

    Take this file f.x. : http://firmamappen.dk/media/314645988461459_2243.png

    It is this one: http://prntscr.com/bok29c

  • Richard Soeteman 4045 posts 12898 karma points MVP 2x
    Jul 04, 2016 @ 09:07
    Richard Soeteman
    0

    And protectcroppedimages is still true? Can you try with pdf files first?

  • Bjørn Nyborg 9 posts 79 karma points
    Jul 04, 2016 @ 09:21
    Bjørn Nyborg
    0

    Yes, this is my full mediaprotect.config file:

    <mediaprotect>
      <version>1.6.2</version>
      <mediaPickers>
        <!--add additional media pickers here-->
        <!--
            <mediapicker alias="media"/>
            <mediapicker alias="filteredmediatreea"/>
           -->
      </mediaPickers>
      <showimagesForUmbracoUsers>false</showimagesForUmbracoUsers>
      <enableLogging logPublicMedia="false" csvDelimiter=";" csvStringIndicator="&quot;">true</enableLogging>
      <disableMediaProtectDialog>False</disableMediaProtectDialog>
      <!--Only enable protectCropperImages when you need to protect cropper images-->
      <protectCropperImages>true</protectCropperImages>
      <!--When true there will be no returnUrl querystring appended to the url login url-->
      <disableReturnUrl>False</disableReturnUrl>
      <!--Id of the default login page -->
      <defaultLoginNode>1067</defaultLoginNode>
      <!--Id of the default not authorized page -->
      <defaultErrorNode>1067</defaultErrorNode>
    </mediaprotect>
    

    The first 2 files i uploaded through the backend worked just fine and was protected, but when i uploaded one from the frontend it doesnt work, this is the pdf: http://firmamappen.dk/media/4146762376286454_2243.pdf

    This is the media section: http://prntscr.com/bokadg

  • Richard Soeteman 4045 posts 12898 karma points MVP 2x
    Jul 04, 2016 @ 09:27
    Richard Soeteman
    0

    Interesting that an uploaded item isn't protected. Is that the case for all protected files that are failing? What is the filename in Umbraco of this pdf?

  • Bjørn Nyborg 9 posts 79 karma points
    Jul 04, 2016 @ 09:37
    Bjørn Nyborg
    0

    Its the one with the red cross in the screenshot.

    The url is: http://firmamappen.dk/media/4146762376286454_2243.pdf

    It seems like that now its only a problem when i upload from the frontend.

  • Richard Soeteman 4045 posts 12898 karma points MVP 2x
    Jul 04, 2016 @ 09:43
    Richard Soeteman
    0

    I think Something in the upload module is not ok.

    Normal file structure is /media/foldername/filename What happens if you replace the file in the backend with another filename?

  • Bjørn Nyborg 9 posts 79 karma points
    Jul 04, 2016 @ 09:49
    Bjørn Nyborg
    0

    Nothing new, when i change the filename the path stays the same. And the access still fails.

    Does Medieprotect depend on the folder structure? Because i have written a custom upload script for the frontend uploader so that i dont have to use the umbraco /10xx/filename.pdf structure. But as you can see i still add the file in the media section just as the files uploaded through the backend. And they all still lives in the /media folder.

  • Richard Soeteman 4045 posts 12898 karma points MVP 2x
    Jul 04, 2016 @ 09:58
    Richard Soeteman
    0

    No it does not depend on folder structure but that is the thing that is strange on your end. During validation it checks if the file exists on disk, of it's in the /media folder and it needs to find the id based on filename in the database.. I think somewhere in the upload module something is not stored correctly.

    New pdf's from the back-end work I assume?

    Maybe you can share the upload code?

  • Bjørn Nyborg 9 posts 79 karma points
    Jul 04, 2016 @ 10:03
    Bjørn Nyborg
    0

    The new pdf's from backend are working correctly yes.

    Here is my upload script:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @using EmailTemplate;
    @{
    
        var ContentService = ApplicationContext.Current.Services.ContentService;
        var MemberService = ApplicationContext.Current.Services.MemberService;
    
        var currentUser = Members.GetCurrentMember();
        var company = CurrentPage.AncestorOrSelf("Company");
        if(currentUser != null){
            var currentMember = MemberService.GetById(currentUser.Id);
            if(!String.IsNullOrEmpty(currentMember.GetValue("company").ToString())){
                company = Umbraco.Content(currentMember.GetValue("company").ToString());
            }
        }
    
    
        var months = 12-DateTime.Now.Month;
    }
    
    
    @if(DateTime.Now < company.nextBillingDate){
    
        @* File *@
    
        var config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/");
        var section = (System.Web.Configuration.SystemWebSectionGroup)config.GetSectionGroup("system.web");
        int maxRequestLengthMB = section.HttpRuntime.MaxRequestLength/1024;
        int maxRequestLengthBytes = section.HttpRuntime.MaxRequestLength*1024;
    
        var docCount = company.Descendants("File").Count() + company.Descendants("Document").Count();
    
        if(IsPost && !String.IsNullOrEmpty(Request.Form["create-file"]) && Request.Files.Count > 0){
            var fileName = "";
            @* Upload file *@
            var MediaService = ApplicationContext.Current.Services.MediaService;
            var fileSavePath = "";
            var uploadedFile = Request.Files[0];  
            string[] ext = Path.GetFileName(uploadedFile.FileName).Split('.');
    
            fileName = (company.Descendants("File").Count() +1) + "_" + (DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds.ToString().Replace(",","_") + "_" +company.Id+"."+ext[1];
    
            fileSavePath = Server.MapPath("~/media/" + fileName);
            if(ext[1] == "jpg" || ext[1] == "png" || ext[1] == "gif" || ext[1] == "pdf"){
                uploadedFile.SaveAs(fileSavePath);
                var localSavePath = Url.Content("~/media/" + fileName);
                FileInfo info = new FileInfo(fileSavePath);
    
                var UploadedMedia = MediaService.CreateMedia(fileName, Umbraco.Media(CurrentPage.AncestorOrSelf(2).company_gallery).Id, "File", 0);
    
                @* Create media *@
                UploadedMedia.SetValue("umbracoFile",localSavePath);
                UploadedMedia.SetValue("umbracoBytes",info.Length);
                UploadedMedia.SetValue("umbracoExtension",ext[1]);
    
                MediaService.Save(UploadedMedia, 0, true);
    
                @* Create content node *@
                var newFile = ContentService.CreateContent(Request.Form["file-name"],CurrentPage.Id,"File",0);
                    newFile.SetValue("fileMedia",UploadedMedia.Id);
                ContentService.SaveAndPublish(newFile,0,true);
    
                var success = Server.UrlEncode(newFile.Name+" blev uploaded");
                Response.Redirect(CurrentPage.Url+"?success="+success);
            } else {
                var error = Server.UrlEncode("Vi tager kun imod billeder og pdf'er!");
                Response.Redirect(CurrentPage.Url+"?error="+error);
            }
    
    
        }   
        <div class="modal fade" id="create-file">
            <div class="modal-dialog">
                <div class="modal-content">
                    <form method="post" enctype="multipart/form-data" class="validate">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal">&times;</button>
                            <h4 class="modal-title">Opret et dokument</h4>
                        </div>
                        <div class="modal-body">
    
                            @if(company.documents > docCount){
                                <div class="form-group">
                                    <input class="form-control" type="text" placeholder="Hvad skal filen hedde?" name="file-name" required>
                                </div>
                                <div class="form-group">
                                    <label>Max @maxRequestLengthMB MB</label>
                                    <input type="file" accept="application/pdf,image/jpg,image/png" id="file-upload" name="file-upload" required>
                                </div>
                                <div class="form-group">    
                                    <div class="alert alert-danger" id="file-error">
                                        <span class="error-text"></span><br>
                                        Er din fil for stor? Prøv <a href="http://smallpdf.com/compress-pdf">smallpdf.com</a>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="alert alert-warning">
                                        Vi tager kun imod billeder og pdf'er!
                                    </div>
                                </div>
                            } else {
                                <div class="form-group">
                                    <div class="alert alert-danger">
                                        Du har ikke plads til flere dokumenter!
                                    </div>
                                </div>
                            }
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">Luk</button>
                            @if(company.documents > docCount){  
                                <button type="submit" name="create-file" value="submit" class="btn btn-success">Gem <i class="fa fa-save"></i></button>
                            }
                        </div>
                    </form>
                </div>
            </div>
        </div>  
    
    }                   
    @* End of functions only avaliable when payed *@
    

    Do you see anything is stored wrong? Solving this mystery would be awesome!

  • Richard Soeteman 4045 posts 12898 karma points MVP 2x
    Jul 04, 2016 @ 10:58
    Richard Soeteman
    0

    CMSImport is using this method. It assigns stream and that takes care of storing the file correctly and setting the correct values. I think there is a mismatch if you set the file manually. Maybe you can change that?

    using (var fs = File.OpenRead(filePath))
            {
                fileName = Path.GetFileName(filePath);
                media.SetValue("umbracoFile", fileName, fs);
            }
        ApplicationContext.Current.Services.MediaService.Save(media);
    
  • Bjørn Nyborg 9 posts 79 karma points
    Jul 04, 2016 @ 11:24
    Bjørn Nyborg
    0

    Hmm... The SetValue doesnt accept 3 arguments.

    No overload for method 'SetValue' takes '3' arguments
    

    So how did you get that to work? :)

    And how do you get the filePath without saving the file on the server first?

    I have this now:

    if(IsPost && !String.IsNullOrEmpty(Request.Form["create-file"]) && Request.Files.Count > 0){
        var fileName = "";
    
        @* Upload file *@
        var MediaService = ApplicationContext.Current.Services.MediaService;
        var fileSavePath = "";
        var uploadedFile = Request.Files[0];  
        string[] ext = Path.GetFileName(uploadedFile.FileName).Split('.');
    
        fileName = (company.Descendants("File").Count() +1) + "_" + (DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds.ToString().Replace(",","_") + "_" +company.Id+"."+ext[1];
    
        fileSavePath = Server.MapPath("~/media/" + fileName);
    
        if(ext[1] == "jpg" || ext[1] == "png" || ext[1] == "gif" || ext[1] == "pdf"){
    
            uploadedFile.SaveAs(fileSavePath);
    
            var localSavePath = Url.Content("~/media/" + fileName);
            FileInfo info = new FileInfo(fileSavePath);
    
            var UploadedMedia = MediaService.CreateMedia(fileName, Umbraco.Media(CurrentPage.AncestorOrSelf(2).company_gallery).Id, "File", 0);
    
            using (var fs = System.IO.File.OpenRead(uploadedFile)){
                UploadedMedia.SetValue("umbracoFile", fileName, fs);
            }
    
            UploadedMedia.SetValue("umbracoBytes",info.Length);
            UploadedMedia.SetValue("umbracoExtension",ext[1]);
    
            MediaService.Save(UploadedMedia, 0, true);
    
            var newFile = ContentService.CreateContent(Request.Form["file-name"],CurrentPage.Id,"File",0);
                newFile.SetValue("fileMedia",UploadedMedia.Id);
            ContentService.SaveAndPublish(newFile,0,true);
    
            var success = Server.UrlEncode(uploadedFile +" blev uploaded");
            Response.Redirect(CurrentPage.Url+"?success="+success);
        } else {
            var error = Server.UrlEncode("Vi tager kun imod billeder og pdf'er!");
            Response.Redirect(CurrentPage.Url+"?error="+error);
        }
    
  • Richard Soeteman 4045 posts 12898 karma points MVP 2x
    Jul 04, 2016 @ 11:41
    Richard Soeteman
    0

    Weird, Think I'm compiling against an older version that still has some code to handle this. anyway, SetPropertyValue(string propertyTypeAlias, HttpPostedFile value) should work for you I think.

Please Sign in or register to post replies

Write your reply to:

Draft