I would like to know if it would be possible to transform videos and audios in Base64, I already asked a question related to transform image in Base64 and you helped me, but now I need to do the same for audio and video, I had thought it would be the same process of the image but it is not working.
This is the link from my previous question and the solution I found also posted here
The application I'm developing is mobile, I need to convert it to send to the server and then the server will unconvert and work with the file.
This is the code of my server side that receives the Base64 file as the parameter and the name to convert and save to a directory:
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
System.IO.Stream body = context.Request.InputStream;
System.Text.Encoding encoding = context.Request.ContentEncoding;
System.IO.StreamReader reader = new System.IO.StreamReader(body, encoding);
//obtem postDATA
string postData = reader.ReadToEnd();
NameValueCollection param = HttpUtility.ParseQueryString(postData);
//params
// filename = nome do arquivo
// d = conteudo binario codificado em base64
// UserId = id do usuario
// Date = data no formato json
//salva arquivo
if (param["filename"] != null && param["d"] != null)
{
Directory.CreateDirectory("C:\Uploads");
string strSaveLocation = ("C:\Uploads") + "\" + param["filename"];
FileStream fs1 = new FileStream(strSaveLocation, FileMode.OpenOrCreate, FileAccess.Write);
BinaryWriter bw = new BinaryWriter(fs1);
try
{
//tenta converter vindo em base64
byte[] decbuff = Convert.FromBase64String(param["d"]);
bw.Write(decbuff);
}
catch (Exception e)
{
//failover - salva sem conversao
bw.Write(param["d"]);
}
bw.Close();
fs1.Close();
//responde OK
context.Response.Write("{\"StatusRetorno\":0,\"MensagemRetorno\":\"Operacao_Realizada\",\"idSync\":}");
}
else
{
//responde erro
context.Response.Write("{\"StatusRetorno\":1,\"MensagemRetorno\":\"could not save file\"}");
}
body.Close();
reader.Close();
}