Copied to clipboard

Flag this post as spam?

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


  • David 32 posts 52 karma points
    Jan 14, 2013 @ 12:39
    David
    0

    Contour speed

    On development servers contour works great.

    On production (third party hosting) the submission of a form with a lot of images takes an agonising amount of time or more often times out.

    I recognise that this is most likely an issue with the hosting provider but was wondering if anyone else had this problem and what needed resolving.

    I submitted a form with around 15 images which takes a long time to submit (as expected with 15 images) and monitored the Umbraco/plugins/umbracoContour/files/ folder (refreshing every 20 seconds) expecting to see each file added but none were.

    Could this be a permissions issue?

    Is it possible to change the location where a file should be saved to give "looser" permissions to the folder.  The images themselves aren't sensitive information.

  • Tim Geyssens 6562 posts 15373 karma points MVP 2x c-trib
    Jan 14, 2013 @ 13:08
    Tim Geyssens
    0

    Hi,

    The file location can not be changed so make sure the permissions on that folder are set as needed. 

    If you upload a file to the backoffice does it also take so long? 

    Sounds more like an environment issue...

  • David 32 posts 52 karma points
    Jan 14, 2013 @ 14:14
    David
    0

    The issue I think is related to the file size.

    Each photo uploaded has an average size of 1.5mb.  I've tried changing the max request length for httpruntime and also the max json length but it hasn't helped.

  • Tim Geyssens 6562 posts 15373 karma points MVP 2x c-trib
    Jan 14, 2013 @ 14:31
    Tim Geyssens
    0

    Yup 15 images at 1.5 mb sounds pretty big, updating max request lenght should help with the timeout 

  • David 32 posts 52 karma points
    Jan 16, 2013 @ 18:42
    David
    0

    Is there a way to resize the image client side?

  • Tim Geyssens 6562 posts 15373 karma points MVP 2x c-trib
    Jan 16, 2013 @ 18:47
    Tim Geyssens
    0

    Yup should be possible with html5 http://stackoverflow.com/questions/10333971/html5-pre-resize-images-before-uploading

    So u custom image upload fieldtype... 

  • David 32 posts 52 karma points
    Jan 24, 2013 @ 12:26
    David
    0

    Hi Tim, thanks for the tip.

    I implemented a custom field type and it works great, from 1.5mb to 100kb!

    It works perfectly in a desktop web browser.

    When I try to use it with an IPad it works fine when selecting "chosse existing" but when I select "Take photo" it can cause the broswer to crash when submitting the page.  It happens both in safari and chrome.

    I was wondering if anyone else had this problem?  It's proving difficult to debug.

  • Tim Geyssens 6562 posts 15373 karma points MVP 2x c-trib
    Jan 24, 2013 @ 12:33
    Tim Geyssens
    0

    Nice nice, any chance you can share that one? 

     

  • David 32 posts 52 karma points
    Jan 24, 2013 @ 12:47
    David
    0

    yes no problem, on this thread or somewhere else? (still quite new)

  • Tim Geyssens 6562 posts 15373 karma points MVP 2x c-trib
    Jan 24, 2013 @ 12:49
    Tim Geyssens
    0

    Sure where ever you want :) would love to give that a try ;)

  • David 32 posts 52 karma points
    Jan 24, 2013 @ 13:01
    David
    0
    Ok here goes. . .
    View
    -----------------------------------------
    @model Umbraco.Forms.Mvc.Models.FieldViewModel
                   
    <input type="file" name="@{@Model.Name}_Dummy" id="@{@Model.Name}_Dummy" onchange="resize('@{@Model.Name}_Dummy','@Model.Id')" @if(Model.Mandatory){<text> data-val="true" data-val-required="@Model.RequiredErrorMessage"</text>}/>
    <input type="hidden" name="@Model.Name" id="@Model.Id"/>
    @if (!string.IsNullOrEmpty(Model.Value))
    {
     <br />
     <a href="@Model.Value" target"_blank">Show current file</a>
     <input type="hidden" name="@{@Model.Name}_file" value="@Model.Value" />
        
        
    }
    -----------------------------------------
  • David 32 posts 52 karma points
    Jan 24, 2013 @ 13:03
    David
    0

    Javascript added to Forms.cshtml

    -----------------------------------------

    <script type="text/javascript">        

            function resize(inputName, hiddenInput) {

                if (window.File && window.FileReader && window.FileList && window.Blob) {

                    var file = document.getElementById(inputName).files[0];

                    var reader = new FileReader();

                    reader.onloadend = function () {

     

                        var tempImg = new Image();

                        tempImg.src = reader.result;

                        tempImg.onload = function () {

     

                            var MAX_WIDTH = 800;

                            var MAX_HEIGHT = 600;

                            var tempW = tempImg.width;

                            var tempH = tempImg.height;

                            if (tempW > tempH) {

                                if (tempW > MAX_WIDTH) {

                                    tempH *= MAX_WIDTH / tempW;

                                    tempW = MAX_WIDTH;

                                }

                            } else {

                                if (tempH > MAX_HEIGHT) {

                                    tempW *= MAX_HEIGHT / tempH;

                                    tempH = MAX_HEIGHT;

                                }

                            }

     

                            var canvas = document.createElement('canvas');

                            canvas.width = tempW;

                            canvas.height = tempH;

                            var ctx = canvas.getContext("2d");

                            ctx.drawImage(this, 0, 0, tempW, tempH);

                            var dataURL = canvas.toDataURL("image/jpeg");                       

                            var hidden = document.getElementById(hiddenInput)

                            hidden.value = file.name + "|SEP|" + dataURL;        

                        }

     

                    }

                    reader.readAsDataURL(file);

                } else {

                    alert('The File APIs are not fully supported in this browser.');

                }

            }

        </script>

    -----------------------------------------

  • David 32 posts 52 karma points
    Jan 24, 2013 @ 13:08
    David
    0

    Custom FieldType ProcessValue override

    ---------------

    public override List<object> ProcessValue(HttpContextBase httpContext)

            {

                List<object> vals = new List<object>();

                bool filesaved = false;          

                var field = httpContext.Request[this.AssociatedField.Id.ToString()];

                if (!string.IsNullOrWhiteSpace(field))

                {

                    var fieldValues= field.Split(new string[] { "|SEP|" }, StringSplitOptions.RemoveEmptyEntries);

                    var imageName = fieldValues[0];

                    var dataurl = fieldValues[1];

                    var data = dataurl.Substring(dataurl.IndexOf(",") + 1);

                    if (!string.IsNullOrEmpty(data))

                    {

                        var fileBytes = Convert.FromBase64String(data);

                        string dir = Configuration.Path + "/files/" + Guid.NewGuid().ToString() + "/";

                        if (!Directory.Exists(httpContext.Server.MapPath(dir)))

                        {

                            Directory.CreateDirectory(httpContext.Server.MapPath(dir));

                        }

                        File.WriteAllBytes(httpContext.Server.MapPath(dir + imageName), fileBytes);

     

                        vals.Add(dir + imageName);

                        filesaved = true;

                    }               

                }

                if (!filesaved)

                {

                    vals.Add(httpContext.Request[this.AssociatedField.Id.ToString() + "_file"] ?? "");

                }

                return vals;

            }

     

    ----------------

  • Tim Geyssens 6562 posts 15373 karma points MVP 2x c-trib
    Jan 24, 2013 @ 13:09
    Tim Geyssens
    0

    Cool will give it a try :)

  • David 32 posts 52 karma points
    Jan 24, 2013 @ 13:20
    David
    0

    Thanks Tim.

    It's stange that the browers completely crash (shutdown) on the ipad.  No error on the page.

  • Tim Geyssens 6562 posts 15373 karma points MVP 2x c-trib
    Jan 24, 2013 @ 13:35
    Tim Geyssens
    0

    Yeah works good on a desktop :) not sure how to fix on ipad

  • David 32 posts 52 karma points
    Jan 24, 2013 @ 14:22
    David
    0

    :-(

    The workaround is to choose an existing image which would require switching between the camera app and website, not ideal.

    The problem does not happen with the standard file upload contour provides.

  • Tim Geyssens 6562 posts 15373 karma points MVP 2x c-trib
    Jan 24, 2013 @ 14:28
    Tim Geyssens
    0

    Yeah must be due to the use of html5 canvas... 

  • David 32 posts 52 karma points
    Jan 24, 2013 @ 14:34
    David
    0

    On my dev server i put in some javascript alerts to see if the image was resized correctly which it is.  So it is able to resize the image taken at the time of selecting it.

  • David 32 posts 52 karma points
    Jan 24, 2013 @ 16:36
    David
    0

    It uploads the images for the page before crashing.

  • Tim Geyssens 6562 posts 15373 karma points MVP 2x c-trib
    Jan 24, 2013 @ 17:18
    Tim Geyssens
    0

    Hmm not sure why it would crash then...expected it to be the html 5 canvas thing

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies