如何使用字符串数据类型存储和检索图像 [英] How to store and retrive image using string data type

查看:53
本文介绍了如何使用字符串数据类型存储和检索图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的报复模式: -



公共类RegisterViewModel 
{
[必需]
[EmailAddress]
[显示(姓名=电子邮件)]
公共字符串电子邮件{get;组; }
公共字符串FirstName {get;组; }
[必需]
公共字符串MiddleName {get;组; }
[必需]
公共字符串LastName {get;组; }
[必需]
public string Gender {get;组; }
[必需]
[DataType(DataType.Date)]
public string DOB {get;组; }
public string Profile {get;组; }
[必需]
[RegularExpression(^ [0-9] {12} $)]
public decimal Mobile {get;组; }
[必需]
公共字符串地址{get;组; }
[必填]

public string City {get;组; }
[必需]

public string State {get;组; }


[必需]
[StringLength(100,ErrorMessage ={0}必须至少{2}个字符。,MinimumLength = 6)]
[DataType(DataType.Password)]
[显示(名称=密码)]
公共字符串密码{get;组; }

[DataType(DataType.Password)]
[显示(名称=确认密码)]
[比较(密码,ErrorMessage =密码和确认)密码不匹配。)]
public string ConfirmPassword {get;组; }
}







这里: -



 public string Profile {get;组; } 

是我要存储图像路径的属性



这是我的控制器: -



 private ApplicationDbContext db = new ApplicationDbContext(); 

//获取:/帐户/注册
[AllowAnonymous]
public ActionResult Register()
{
ViewBag.state = db.allofstate.Select (C => new SelectListItem
{
Value = C.States,
Text = C.States
})。ToList();
return View();
}

//
// POST:/账户/注册
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task< ActionResult>注册(RegisterViewModel模型)
{
if(ModelState.IsValid)
{
var user = new ApplicationUser {UserName = model.Email,Email = model.Email,FirstName = model .FirstName,MiddleName = model.MiddleName,LastName = model.LastName,Gender = model.Gender,DOB = model.DOB,Profile = model.Profile,Mobile = model.Mobile,Address = model.Address,City = model.City ,State = model.State};
var result = await UserManager.CreateAsync(user,model.Password);
using(ApplicationDbContext db = new ApplicationDbContext())

if(result.Succeeded)
{
await SignInManager.SignInAsync(user,isPersistent:false,rememberBrowser:假);

//有关如何启用帐户确认和密码重置的详细信息,请访问http://go.microsoft.com/fwlink/?LinkID=320771
//发送电子邮件至此链接
//字符串代码= await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
// var callbackUrl = Url.Action(ConfirmEmail,Account,new {userId = user.Id,code = code},protocol:Request.Url.Scheme);
//等待UserManager.SendEmailAsync(user.Id,确认您的帐户,请点击< a href = \+ callbackUrl +\>来确认您的帐户< / a> ;);

返回RedirectToAction(Index,Home);
}
AddErrors(result);
}

//如果我们到目前为止,有些事情失败,重新显示形式
返回View(模型);
}





我尝试过:



i尝试使用byte但我想存储图像路径



因为我想在特定用户登录时检索该图像

解决方案

)]
公共小数移动{get; set;}
[必需]
公共字符串地址{get; set;}
[必需]

公共字符串City {get; set;}
[必需]

public string State {get; set; }


[必需]
[StringLength(100,ErrorMessage ={0}必须至少{2}个字符。,MinimumLength = 6)]
[DataType(DataType.Password)]
[显示(名称=密码)]
公共字符串密码{get; set;}

[DataType(DataType) .Password)]
[显示(名称=确认密码)]
[比较(密码,错误消息= 密码和确认密码不匹配。)]
public string ConfirmPassword {get;组; }
}







这里: -



 public string Profile {get;组; } 

是我要存储图像路径的属性



这是我的控制器: -



 private ApplicationDbContext db = new ApplicationDbContext(); 

//获取:/帐户/注册
[AllowAnonymous]
public ActionResult Register()
{
ViewBag.state = db.allofstate.Select (C => new SelectListItem
{
Value = C.States,
Text = C.States
})。ToList();
return View();
}

//
// POST:/账户/注册
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task< ActionResult>注册(RegisterViewModel模型)
{
if(ModelState.IsValid)
{
var user = new ApplicationUser {UserName = model.Email,Email = model.Email,FirstName = model .FirstName,MiddleName = model.MiddleName,LastName = model.LastName,Gender = model.Gender,DOB = model.DOB,Profile = model.Profile,Mobile = model.Mobile,Address = model.Address,City = model.City ,State = model.State};
var result = await UserManager.CreateAsync(user,model.Password);
using(ApplicationDbContext db = new ApplicationDbContext())

if(result.Succeeded)
{
await SignInManager.SignInAsync(user,isPersistent:false,rememberBrowser:假);

//有关如何启用帐户确认和密码重置的详细信息,请访问http://go.microsoft.com/fwlink/?LinkID=320771
//发送电子邮件至此链接
//字符串代码= await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
// var callbackUrl = Url.Action(ConfirmEmail,Account,new {userId = user.Id,code = code},protocol:Request.Url.Scheme);
//等待UserManager.SendEmailAsync(user.Id,确认您的帐户,请点击< a href = \+ callbackUrl +\>来确认您的帐户< / a> ;);

返回RedirectToAction(Index,Home);
}
AddErrors(result);
}

//如果我们到目前为止,有些事情失败,重新显示形式
返回View(模型);
}





我尝试过:



i尝试使用byte但我想存储图像路径



因为我想在特定用户登录时检索该图像


字节流的Base64编码 [ ^ ]

here is my regitration model :-

public class RegisterViewModel
   {
       [Required]
       [EmailAddress]
       [Display(Name = "Email")]
       public string Email { get; set; }
       public string FirstName { get; set; }
       [Required]
       public string MiddleName { get; set; }
       [Required]
       public string LastName { get; set; }
       [Required]
       public string Gender { get; set; }
       [Required]
       [DataType(DataType.Date)]
       public string DOB { get; set; }
       public string Profile { get; set; }
       [Required]
       [RegularExpression("^[0-9]{12}$")]
       public decimal Mobile { get; set; }
       [Required]
       public string Address { get; set; }
       [Required]

       public string City { get; set; }
       [Required]

       public string State { get; set; }


       [Required]
       [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
       [DataType(DataType.Password)]
       [Display(Name = "Password")]
       public string Password { get; set; }

       [DataType(DataType.Password)]
       [Display(Name = "Confirm password")]
       [Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
       public string ConfirmPassword { get; set; }
   }




here :-

public string Profile { get; set; }

is the property where i want to store the path of image

here is my controller :-

private ApplicationDbContext db = new ApplicationDbContext();

       // GET: /Account/Register
       [AllowAnonymous]
       public ActionResult Register()
       {
           ViewBag.state = db.allofstate.Select(C => new SelectListItem
           {
               Value = C.States,
               Text = C.States
           }).ToList();
           return View();
       }

       //
       // POST: /Account/Register
       [HttpPost]
       [AllowAnonymous]
       [ValidateAntiForgeryToken]
       public async Task<ActionResult> Register(RegisterViewModel model)
       {
           if (ModelState.IsValid)
           {
               var user = new ApplicationUser { UserName = model.Email, Email = model.Email, FirstName = model.FirstName, MiddleName = model.MiddleName, LastName = model.LastName, Gender = model.Gender, DOB = model.DOB, Profile = model.Profile, Mobile = model.Mobile, Address = model.Address, City = model.City, State = model.State };
               var result = await UserManager.CreateAsync(user, model.Password);
               using (ApplicationDbContext db = new ApplicationDbContext())

               if (result.Succeeded)
               {
                   await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);

                   // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                   // Send an email with this link
                   // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                   // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                   // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                   return RedirectToAction("Index", "Home");
               }
               AddErrors(result);
           }

           // If we got this far, something failed, redisplay form
           return View(model);
       }



What I have tried:

i have tried with using byte but i want to store images path

because i want to retrive that image when perticular user logs in

解决方案

")] public decimal Mobile { get; set; } [Required] public string Address { get; set; } [Required] public string City { get; set; } [Required] public string State { get; set; } [Required] [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)] [DataType(DataType.Password)] [Display(Name = "Password")] public string Password { get; set; } [DataType(DataType.Password)] [Display(Name = "Confirm password")] [Compare("Password", ErrorMessage = "The password and confirmation password do not match.")] public string ConfirmPassword { get; set; } }




here :-

public string Profile { get; set; }

is the property where i want to store the path of image

here is my controller :-

private ApplicationDbContext db = new ApplicationDbContext();

       // GET: /Account/Register
       [AllowAnonymous]
       public ActionResult Register()
       {
           ViewBag.state = db.allofstate.Select(C => new SelectListItem
           {
               Value = C.States,
               Text = C.States
           }).ToList();
           return View();
       }

       //
       // POST: /Account/Register
       [HttpPost]
       [AllowAnonymous]
       [ValidateAntiForgeryToken]
       public async Task<ActionResult> Register(RegisterViewModel model)
       {
           if (ModelState.IsValid)
           {
               var user = new ApplicationUser { UserName = model.Email, Email = model.Email, FirstName = model.FirstName, MiddleName = model.MiddleName, LastName = model.LastName, Gender = model.Gender, DOB = model.DOB, Profile = model.Profile, Mobile = model.Mobile, Address = model.Address, City = model.City, State = model.State };
               var result = await UserManager.CreateAsync(user, model.Password);
               using (ApplicationDbContext db = new ApplicationDbContext())

               if (result.Succeeded)
               {
                   await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);

                   // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                   // Send an email with this link
                   // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                   // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                   // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                   return RedirectToAction("Index", "Home");
               }
               AddErrors(result);
           }

           // If we got this far, something failed, redisplay form
           return View(model);
       }



What I have tried:

i have tried with using byte but i want to store images path

because i want to retrive that image when perticular user logs in


Base64 encoding of a bytestream[^]


这篇关于如何使用字符串数据类型存储和检索图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆