c# - 使用 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# 中使用croppie.js 的完整帖子
设置croppie的功能,
裁剪图像的功能,
然后通过ajax发送图片日期到web方法,
将图像数据转换为图像并将其保存在文件夹中。
这是链接, https://shaktisinghcheema.com/image-upload-with-cropping/
另外,在将图像数据发送到 Web 方法时,您可能会遇到超时问题,以下是解决方法的链接: Error while sent base64 string through json
我希望这可以帮助解决这个问题的人。
推荐阅读
- blender - 为什么搅拌机中的纹理不适用于所有部分?
- python - 从py到exe的加密程序
- asp.net - ASP.Net Core 2 ServiceProviderOptions.ValidateScopes 属性
- django - Django Rest Framework + Postman + JSON 解析错误
- python - 从新写入的文件中读取的 Python 在模块中不起作用
- c# - Unity - 四元数最大值始终为“1.0”,最小值始终为“-1.0”
- vba - 遍历单元格以更改单元格颜色太慢
- c# - Unity 3d Admob 仅显示测试广告
- java - 如何在 OpenIMAJ 中使用自定义字体
- mysql - 使用 Knex 通过 Waterline/Sails 进行迁移