简体   繁体   中英

Sending a base64 data image via form POST

I have two images in the form of (somewhat):

<img src="data: base64, OIJQWEFOIJQWEFOIJQWEF..." />
<img src="data: base64, OIJQWEFOIJQWEFOIJQWEF..." />

I have no choice in the matter, these images are always going to be set as base64 data.

If I were to POST these using some client side magic, how can I convert the strings to actual images?

public ActionResult Combine(string imageA, string imageB)
{
    // imageA and imageB would be the strings.
    return View();
}

Use Convert.FromBase64String method.
This method:

Converts the specified string, which encodes binary data as base-64 digits, to an equivalent 8-bit unsigned integer array.

Then you can use WebImage class from System.Web.Helpers.dll assembly to convert byte array to actual image and perform some manipulations on it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM