Quantcast
Channel: SharePoint 2010 - Development and Programming forum
Viewing all articles
Browse latest Browse all 11571

jQuery jCrop in Server Farm

$
0
0

I have created an application page that uploads and crops an image using jQuery jCrop... this works great on our Dev server which is only one server.

Once I deploy to our QA environment the crop does not always work... I think its because the cropped image only exists on the server where the crop happened.  So sometimes the image crop is successful and other times its not.

Is there anything I can do to make sure I can get the image to crop every time?

protected void btnCropImage_Click(object sender, EventArgs e)
        {
            int x = Convert.ToInt32(Page.Request["jCropX"]);
            int y = Convert.ToInt32(Page.Request["jCropY"]);
            int w = Convert.ToInt32(Page.Request["jCropW"]);
            int h = Convert.ToInt32(Page.Request["jCropH"]);

            string strListID = Request.QueryString["ListId"];
            //string strWebURL = Request.QueryString["SiteUrl"];
            string strItemID = Request.QueryString["ItemId"];

            lblErr.Style.Add(HtmlTextWriterStyle.Color, "Red");
            lblErr.Style.Add(HtmlTextWriterStyle.FontSize, "11px");
            lblErr.Style.Add(HtmlTextWriterStyle.FontWeight, "bold");
            lblErr.Visible = true;

            //SPSecurity.RunWithElevatedPrivileges(delegate()
            //{
                try
                {
                    using (SPSite site = new SPSite(this.Site.Url))
                    {
                        using (SPWeb web = site.OpenWeb(this.Web.ServerRelativeUrl))
                        {

                            try
                            {
                                web.AllowUnsafeUpdates = true;

                                SPList list = web.Lists[new Guid(strListID)];
                                SPListItem item = list.Items.GetItemById(Convert.ToInt32(strItemID));
                                SPFile file = item.File;

                                if (list.WorkflowAssociations.Count > 0)
                                {
                                    //dont crop as it can effect workflow
                                    lblErr.Text = "The document library this image belongs to has workflow enabled. Please disable workflows on this document library to enable cropping";

                                    btnCropImage.Enabled = false;
                                    btnCropImageTop.Enabled = false;
                                    return;
                                }
                                else
                                {
                                    lblErr.Visible = false;
                                }

                                if (file.CheckOutStatus != SPFile.SPCheckOutStatus.None)
                                {
                                    file.CheckIn("");
                                }

                                file.CheckOut();

                                //use WebRequest to create stream to the document library file
                                WebRequest reqImg = WebRequest.Create(strImageURL);
                                reqImg.UseDefaultCredentials = true;
                                WebResponse imgResponse = reqImg.GetResponse();
                                StreamReader reader = new StreamReader(imgResponse.GetResponseStream());

                                using (System.Drawing.Image imgOriginal = System.Drawing.Image.FromStream(reader.BaseStream, true))
                                {
                                    using (System.Drawing.Image imgCropped = new System.Drawing.Bitmap(w, h))
                                    {
                                        using (System.Drawing.Graphics graphic = System.Drawing.Graphics.FromImage(imgCropped))
                                        {
                                            graphic.SmoothingMode = SmoothingMode.AntiAlias;
                                            graphic.InterpolationMode = InterpolationMode.HighQualityBicubic;
                                            graphic.PixelOffsetMode = PixelOffsetMode.HighQuality;

                                            System.Drawing.Rectangle rect = new System.Drawing.Rectangle(0, 0, w, h);
                                            graphic.DrawImage(imgOriginal, rect, x, y, w, h, System.Drawing.GraphicsUnit.Pixel);

                                            MemoryStream mstream = new MemoryStream();
                                            imgCropped.Save(mstream, imgOriginal.RawFormat);

                                            MemoryStream msNew = null;
                                            using (msNew = new MemoryStream(mstream.GetBuffer(), 0, mstream.GetBuffer().Length))
                                            {
                                                msNew.Write(mstream.GetBuffer(), 0, mstream.GetBuffer().Length);
                                                list.RootFolder.Files.Add(file.Name, msNew.ToArray(), true);
                                                file.Item.SystemUpdate(false);
                                                file.CheckIn("");
                                            }
                                        }
                                    }
                                }

                                web.AllowUnsafeUpdates = false;
                            }
                            catch (Exception ex)
                            {
                                lblErr.Visible = true;
                                lblErr.Text = ex.Message;
                                if (web.AllowUnsafeUpdates != false)
                                {
                                    web.AllowUnsafeUpdates = false;
                                }
                            }

                        }
                    }
                    Response.Redirect("/_layouts/Insight.Sp.UserProfiles/ImageUploadCrop/EditImageStand.aspx");
                }
                catch (Exception ex)
                {
                    lblErr.Visible = true;
                    lblErr.Text = ex.Message;
                }

            //});
        }

Any help is appreciated!!!


sayitfast


Viewing all articles
Browse latest Browse all 11571

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>