コード例 #1
0
        protected void ZoomImageUploadComplete(object sender, FileUploadCompleteEventArgs e)
        {
            if (e.UploadedFile.IsValid)
            {
                string fullDir = Request.MapPath(UploadDirectory + TempData["ProductId"]);

                if (!Directory.Exists(fullDir))
                {
                    Directory.CreateDirectory(fullDir);
                }

                fullDir = Request.MapPath(UploadDirectory + TempData["ProductId"]) + @"\" + TempData["ColorId"];

                if (!Directory.Exists(fullDir))
                {
                    Directory.CreateDirectory(fullDir);
                }

                string filePath       = UploadDirectory + TempData["ProductId"] + "/" + TempData["ColorId"] + "/" + TempData["FilePrefix"] + e.UploadedFile.FileName;
                string filePathDetail = UploadDirectory + TempData["ProductId"] + "/detail_" + TempData["FilePrefix"] + e.UploadedFile.FileName;

                using (Image original = Image.FromStream(e.UploadedFile.FileContent))
                {
                    PhotoUtils.SaveToJpeg(original, Request.MapPath(filePath));
                    if ((TempData["FilePrefix"] == "imagefrontfirstzoom_") || (TempData["FilePrefix"] == "imagefrontsecondzoom_"))
                    {
                        PhotoUtils.SaveToJpeg(PhotoUtils.Inscribe(original, 200, 200), Request.MapPath(filePathDetail));
                    }
                }

                e.CallbackData = TempData["FilePrefix"] + e.UploadedFile.FileName + "|" + Url.Content(filePath) + "?refresh=" + Guid.NewGuid();
            }
        }
コード例 #2
0
        protected void ImageUploadComplete(object sender, FileUploadCompleteEventArgs e)
        {
            if (e.UploadedFile.IsValid)
            {
                string fullDir = Request.MapPath(UploadDirectory + TempData["ProductId"]);

                if (!Directory.Exists(fullDir))
                {
                    Directory.CreateDirectory(fullDir);
                }

                fullDir = Request.MapPath(UploadDirectory + TempData["ProductId"]) + "/" + TempData["ColorId"];

                if (!Directory.Exists(fullDir))
                {
                    Directory.CreateDirectory(fullDir);
                }

                string filePath          = UploadDirectory + TempData["ProductId"] + "/" + TempData["ColorId"] + "/" + TempData["FilePrefix"] + e.UploadedFile.FileName;
                string filePathThumbnail = UploadDirectory + TempData["ProductId"] + "/" + TempData["ColorId"] + "/thumb_" + TempData["FilePrefix"] + e.UploadedFile.FileName;

                using (Image original = Image.FromStream(e.UploadedFile.FileContent))
                {
                    PhotoUtils.SaveToJpeg(original, Request.MapPath(filePath));
                }

                e.CallbackData = TempData["FilePrefix"] + e.UploadedFile.FileName + "|" + Url.Content(filePath) + "?refresh=" + Guid.NewGuid();
            }
        }
コード例 #3
0
    string SavePostedFile(UploadedFile uploadedFile)
    {
        string ret          = "";
        string base64String = "";

        if (!uploadedFile.IsValid)
        {
            return(string.Empty);
        }

        string fileName = Path.Combine(MapPath(UploadDirectory), ThumbnailFileName);

        using (Image original = Image.FromStream(uploadedFile.FileContent)) {
            base64String = PhotoUtils.ConvertImageToBase64(original);
            using (Image thumbnail = PhotoUtils.Inscribe(original, 100)) {
                PhotoUtils.SaveToJpeg(thumbnail, fileName);
            }
        }


        ret = string.Format("{0}|{1}", ThumbnailFileName, base64String);

        //return ThumbnailFileName;
        return(ret);
    }
コード例 #4
0
            public static void UploadImage(object sender, FileUploadCompleteEventArgs e)
            {
                if (e.UploadedFile.IsValid)
                {
                    string fileName = e.UploadedFile.FileName;
                    if (fileName.Contains('_'))
                    {
                        fileName = fileName.Replace('_', '-');
                    }
                    string imageNameWithGuid = (Guid.NewGuid()).ToString() + "_" + fileName;
                    string resultFilePath    = UploadImagePath + imageNameWithGuid;
                    using (Image original = Image.FromStream(e.UploadedFile.FileContent))
                        using (Image thumbnail = PhotoUtils.Inscribe(original, 100))
                        {
                            PhotoUtils.SaveToJpeg(thumbnail, resultFilePath);
                        }
                    IUrlResolutionService urlResolver = sender as IUrlResolutionService;
                    if (urlResolver != null)
                    {
                        // e.CallbackData = e.UploadedFile.FileName;
                        e.CallbackData = imageNameWithGuid;
                    }

                    UploadedImageFileName = imageNameWithGuid;
                }
            }
コード例 #5
0
        string SavePostedFile(UploadedFile uploadedFile)
        {
            string ret;
            string base64String;

            if (!uploadedFile.IsValid)
            {
                return(string.Empty);
            }

            var fileName = Path.Combine(MapPath(UploadDirectory), ThumbnailFileName);

            using (System.Drawing.Image original = System.Drawing.Image.FromStream(uploadedFile.FileContent))
            {
                base64String = PhotoUtils.ConvertImageToBase64(original);
                using (System.Drawing.Image thumbnail = PhotoUtils.Inscribe(original, 100))
                {
                    Session["UiImagenUsuario"] = "data:image/png;base64," + PhotoUtils.ConvertImageToBase64(thumbnail);
                    PhotoUtils.SaveToJpeg(thumbnail, fileName);
                }
            }
            ret = string.Format("{0}|{1}", ThumbnailFileName, base64String);

            return(ret);
        }
コード例 #6
0
        protected void ImageHomeUploadComplete(object sender, FileUploadCompleteEventArgs e)
        {
            if (e.UploadedFile.IsValid)
            {
                string filePath = UploadHomeDirectory + TempData["HomeImageName"];

                using (Image original = Image.FromStream(e.UploadedFile.FileContent))
                {
                    PhotoUtils.SaveToJpeg(original, Request.MapPath(filePath));
                }

                e.CallbackData = TempData["HomeImageName"] + "|" + Url.Content(filePath) + "?refresh=" + Guid.NewGuid();
            }
        }
コード例 #7
0
        string SavePostedFile(UploadedFile uploadedFile)
        {
            string ret;
            string base64String;

            if (!uploadedFile.IsValid)
            {
                return(string.Empty);
            }

            var fileName = Path.Combine(MapPath(UploadDirectory), ThumbnailFileName);

            /*using (System.Drawing.Image thumbnail = PhotoUtils.Inscribe(original, 100))
             * {
             *  PhotoUtils.SaveToJpeg(thumbnail, fileName);
             * }
             *
             * /*System.IO.FileInfo info = new System.IO.FileInfo(fileName);
             * string extension = System.IO.Path.GetExtension(uploadedFile.FileName).TrimStart('.');
             * string header = string.Format("data:image/{0};base64,", extension);
             *
             * var imgBase64 = Convert.ToBase64String(uploadedFile.FileBytes);
             * Session["UiLogoCentroDeDistribucion"] = "data:image/png;base64," + imgBase64;
             * return string.Format("{0}{1}", header, imgBase64);*/

            //var imgBase64  = "";
            using (System.Drawing.Image original = System.Drawing.Image.FromStream(uploadedFile.FileContent))
            {
                base64String = PhotoUtils.ConvertImageToBase64(original);
                using (System.Drawing.Image thumbnail = PhotoUtils.Inscribe(original, 100))
                {
                    Session["UiLogoCentroDeDistribucion"] = "data:image/png;base64," + PhotoUtils.ConvertImageToBase64(thumbnail);
                    //ret = string.Format("{0}|{1}", ThumbnailFileName, base64String);
                    PhotoUtils.SaveToJpeg(thumbnail, fileName);
                }
            }

            //Session["UiLogoCentroDeDistribucion"] = "data:image/png;base64," + base64String;
            ret = string.Format("{0}|{1}", ThumbnailFileName, base64String);

            return(ret);
        }