简体   繁体   English

URL编码的Base64编码的文件数据

[英]URL Encoded Base64 Encoded File Data

I'm trying to encode an image url to Base64 in ASP.NET so that that an open source API can process my request. 我正在尝试将图像URL编码为ASP.NET中的Base64,以便开源API可以处理我的请求。 The support team on the open source end of things sent me this code from their PHP system. 开源方面的支持团队从他们的PHP系统向我发送了此代码。 I'm having problem translating that into a C# equivalent. 我在将其转换为C#等效项时遇到问题。

PHP Code: PHP代码:

$data = urlencode(base64_encode(fread(fopen("/tmp/signature.jpg", "r"),      filesize("/tmp/signature.jpg")))); 

Things I have tried so far: 到目前为止我尝试过的事情:

string data = "http://url.com/image.jpg"
byte[] encbuff = HttpUtility.UrlEncodeToBytes(data);
string enc = Convert.ToBase64String(encbuff);
string urlenc = HttpUtility.UrlEncode(data);

Any help would be appreciated, Thank you. 任何帮助将不胜感激,谢谢。

The PHP fopen and fread functions are opening a file and reading its bytes. PHP fopenfread函数正在打开文件并读取其字节。 You're only working with the URL. 您仅使用URL。 You need to download it, or open if it's a local file, first: 您需要下载它,或者如果它是本地文件,则首先打开:

byte[] data;
using (var webClient = new WebClient())
    data = webClient.DownloadData("http://url.com/image.jpg");
string enc = Convert.ToBase64String(data);
string urlenc = HttpUtility.UrlEncode(enc);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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