将图像从文件路径转换为base64字符串 [英] Convert the image from filepath to base64 string

查看:389
本文介绍了将图像从文件路径转换为base64字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我需要将图像文件转换为javascript中的字符串或变量.这对于html 5是必需的.

Hi
I need to conver the image file to string or variable in javascript. This is need for html 5.

推荐答案

如果要上传文件并另存为服务器上的字符串,则应使用上传文件并将流用作字节数组并进行转换转换为base64字符串

您可以使用以下代码

if you want to upload file and save as string on server then you should use upload file and use stream as byte array and convert it to base64 string

you can use following code

<asp:fileupload id="flupUpload" runat="Server"   />
       <asp:button id="Button1" runat="server" onclick="Button1_Click" text="Button"   />







protected void Button1_Click(object sender, EventArgs e)
{

    int iLen = flupUpload.PostedFile.ContentLength;
    byte[] btArr = new byte[iLen];
    flupUpload.PostedFile.InputStream.Read(btArr, 0, iLen);
    Response.Write(Convert.ToBase64String(btArr));
    //      Convert.ToBase64String(btArr) -: this is your base64 string
}





如果您的问题已解决,请标记为解决方案





mark as solution if you problem solved


这篇关于将图像从文件路径转换为base64字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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