我想base64编码一个正在接收的图像,HttpPostedFileBase以便在json对象中发送它,我不知道它是如何完成的......请告诉我如何将其解码回HttpPostedFileBase
我正在使用视图上传照片,然后我在控制器中收到它 HttpPostedFileBase
然后我发送它在一个Http请求,事情很好,但当我收到json对象中的http请求时,照片为null
这是请求:
public ActionResult RegisterUsersCheck(User_all_data user_data)
{
var webAddr = "http://localhost:59305/api/User/RegisterUsersCheck";
var httpWebRequest = (HttpWebRequest)WebRequest.Create(webAddr);
httpWebRequest.ContentType = "application/json; charset=utf-8";
httpWebRequest.Accept = "application/json";
httpWebRequest.Method = "POST";
using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
{
string json = "{ user : { 'FirstName':'" + user_data.user.FirstName +
"','LastName': '" + user_data.user.LastName + "','Email': '" + user_data.user.Email +
"','Password': '" + user_data.user.Password + "','Country': '" + user_data.user.Country +
"','PhoneNumber': '" + user_data.ProfilePicture +
"'},'ProfilePicture': '" + user_data.PhoneNumber + "'}";
streamWriter.Write(json);
streamWriter.Flush();
}
var …Run Code Online (Sandbox Code Playgroud) 我只是尝试使用 c# 创建一个文件并在其中写入。这是我的代码:
public void AddLog (string message, string fn_name)
{
string path = @"E:\" + fn_name +".txt";
if (!File.Exists(path))
{
File.Create(path);
File.Delete(path);
TextWriter tw = new StreamWriter(path);
tw.WriteLine("" + message +"");
tw.Close();
}
else if (File.Exists(path))
{
TextWriter tw = new StreamWriter(path,true);
tw.WriteLine("" + message + "");
tw.Close();
}
}
Run Code Online (Sandbox Code Playgroud)
问题是它总是给我这个例外:
{“该进程无法访问文件“E:\CheckForFriends.txt”,因为它正在被另一个进程使用。”}
在这一行:File.Delete(path);
即使我删除了这一行,它也会在该行给出相同的异常消息:File.Create(path);
那么,有人知道我的代码有什么问题吗?