This article is a mirror article of machine translation, please click here to jump to the original article.

View: 62223|Reply: 6

[ASP.NET] asp.net convert binary Base64 content into images and store them locally

[Copy link]
Posted on 10/23/2015 9:40:36 AM | | | |

The ext and data content in the form data of the headers of the website are received in the background and stored in the upload folder of the root directory of the website.

The code is as follows:

  1. [HttpPost]
  2.         public ActionResult Images()
  3.         {
  4.             if (Request["ext"] == null || Request["data"] == null)
  5.             {
  6.                 return Content("Error");
  7.             }

  8.             string ext = Request["ext"].ToString().Trim();

  9.             var btsdata = Convert.FromBase64String(Request["data"]);

  10.             string uploadDir = Server.MapPath("/Upload/" + Guid.NewGuid().ToString("D") + ext);

  11.             if (!Directory.Exists(uploadDir))
  12.             {
  13.                 Directory.CreateDirectory(uploadDir);
  14.             }

  15.             using (Image img = Image.FromStream(new MemoryStream(btsdata)))
  16.             {
  17.                 img.Save(uploadDir  , ImageFormat.Jpeg);
  18.             }

  19.             return Content("Successed");
  20.         }
Copy code
saveImages.zip (35.24 KB, Number of downloads: 74)




Previous:CPA single-page source code + fake QQ forced video software developed by Yi Language, absolutely exclusive sharing
Next:Compare the performance of the primary key of the Guid field using the self-incremental field in the library
Posted on 11/10/2015 11:17:06 AM |

Make a user avatar upload function
Posted on 10/26/2015 1:42:16 PM |
What's the use of this?
Posted on 11/17/2015 10:31:27 AM |
I upload images using other people's methods
Posted on 1/28/2019 4:14:16 PM |
admin posted on 2015-11-10 11:17
Make a user avatar upload function

It's simple and good
Posted on 6/23/2021 6:51:59 PM |
Thank you~~ Not bad, not bad~
Posted on 7/10/2021 7:31:45 PM |
I upload images using other people's methods
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com