首页 > 解决方案 > 使用 Croppie 裁剪后如何将图像保存在文件夹中(Jquery Image cropper)

问题描述

我正在尝试使用croppie裁剪到文件夹和图像路径后保存图像,但它转换为base64&我也不知道如何将此数据发送到控制器&如何将图像保存到文件夹&它的路径数据库。

我已经尝试保存file.write功能,但它没有将图像数据发送回控制器

public ActionResult AddProduct(Tbl_Product product,HttpPostedFileBase file_photo)
        {
            string name = null;
            string ext = null;           

            if (ModelState.IsValid==true)
            {
                if (file_photo != null)
                {
                    name = Path.GetFileNameWithoutExtension(file_photo.FileName);
                    ext = Path.GetExtension(file_photo.FileName);

                    string path = Path.Combine(Server.MapPath("~/ProductImages"), name + ext);
                    file_photo.SaveAs(path);
                }

                product.ProductImage = name + ext;
                product.CreatedDate = DateTime.Now;
                _unitofwork.GetRepositoryInstance<Tbl_Product>().Add(product);
                return RedirectToAction("Product");
            }
            else
            {
                ViewBag.CategoryList = GetCategory();
                return View();
            }            
        }

我想将图像保存在文件夹和数据库路径中,但它显示 base64 图像

标签: c#asp.netasp.net-mvcasp.net-mvc-5croppie

解决方案


我已经写了一篇关于在 c# 中使用croppie.js 的完整帖子

设置croppie的功能,

裁剪图像的功能,

然后通过ajax发送图片日期到web方法,

将图像数据转换为图像并将其保存在文件夹中。

这是链接, https://shaktisinghcheema.com/image-upload-with-cropping/

另外,在将图像数据发送到 Web 方法时,您可能会遇到超时问题,以下是解决方法的链接: Error while sent base64 string through json

我希望这可以帮助解决这个问题的人。


推荐阅读