Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

Currently i am working on cloud window Azure project, my issue is Image preview is not working on cloud window Azure but it's working on my local development machine. Once it deployed on cloud then image preview and its validation is not working.


Here is the my code -
NOTE - (This code is working fine local IE-9)
HTML5 Code-
  <td>
                            <span class="inpFileWrap">
                                <input type="file" id="customerPic" name="customerPic" tabindex="51" class="inputFile"
                                     önchange="PreviewCustomerImg(this)" /></span>
                            <label id="label" class="note">
                                Select an image file on your computer(100kb max):</label>
                            <label id="imageError" class="error marginTm25 dispNone">
                            </label>
                            @if (Session["customerpic"] != null)
                            {
                                byte[] temp23 = Session["customerpic"] as byte[]; 
                                 <span class="imgExistPrev">
                                    <img style="border:2 ,0,#FFFFFF;padding:50" width="60" height="80" src="data:image/jpg;base64,@(Convert.ToBase64String(temp23))" alt="" />
                                </span>  

                            }
                            <div id="customerPicPreview">
                            </div>
                        </td>

<style type="text/css">
    #customerPicPreview
    {
        filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale);
    }
</style>



JQuery function - 

function PreviewCustomerImg(imgFile) {
        $.ajax({
            type: 'POST',
            cache: false,
            url: '/AddCustomer/VerifyImageSize?CustomerImage=' + imgFile.value,
            success: function (data) {
                var value = data;
                if (value == 1) {
                    //TODO: Shanker needs to take care of this
                    $('#imageError').show().html("Only .jpg , .jpeg, .png files can be uploaded.").removeClass("dispNone");
                    $("#customerPicPreview").hide();
                    return false;

                }
                if (value == 2) {
                    //TODO: Shanker needs to take care of this
                    $('#imageError').show().html("File size should not exceed more than 100KB").removeClass("dispNone"); ;
                    $("#customerPicPreview").hide();
                    return false;
                }
                else {
                    $('#imageError').html("").hide();
                    $("#customerPicPreview").show();
                    var newPreview = document.getElementById("customerPicPreview");
                    newPreview.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = imgFile.value;
                    newPreview.style.width = "100px";
                    newPreview.style.height = "100px";
                }
            }

        });

    }


My Controller Code is  - 

 [HandleError(ExceptionType = typeof(Exception), View = "ApplicationError")]
        public JsonResult VerifyImageSize(string CustomerImage)
        {
            HttpPostedFileBase photo = Request.Files["customerPic"];

            string filenameWithPath = CustomerImage;
            string filename = System.IO.Path.GetFileName(filenameWithPath);
            string e = Path.GetExtension(CustomerImage);
            if (e == null)
            {
                return new JsonResult { Data = 1 };
            }

            string path = Server.MapPath("~/App_Data");
            byte[] imgData = System.IO.File.ReadAllBytes(CustomerImage);
            //Check file extention here
            if (e == ".jpeg" || e == ".jpg" || e == ".png")
            {
                if (imgData.Length > 102400)
                {
                    return new JsonResult { Data = 2 };
                }
                else
                {
                    return new JsonResult { Data = 3 };
                }
            }
            else
            {
                return new JsonResult { Data = 1 };
            }
        }

Thanks
Sandeep
Posted
Updated 1-Feb-13 6:28am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900