Decode base64 to pdf in web API
Web API:=>
NameSpace
==========================================================
using System.Net;
using System.Net.Http;
using System.Web;
using System.Web.Http;
==========================================================
#region Upload Base64 formate and save into database and folder.
[HttpPost]
public HttpResponseMessage updateprofileImage()
{
var httpRequest = HttpContext.Current.Request;
string fileOriginalPath = "~/FileUploaded";
var file64 = httpRequest.Form[0];
string strTutorImg = string.Empty;
if (!string.IsNullOrEmpty(file64))
{
/*where you need to save 64 file*/
string Base64file;
Base64file = DateTime.UtcNow.Ticks + "-" + "base64-" + "decod.pdf";
var filepath1 = httpRequest.MapPath(fileOriginalPath);
filepath1 = Path.Combine(filepath1, System.IO.Path.GetFileName(Base64file));
/*end here */
/*Convert base64 file into pdf file start here*/
Byte[] bytes2 = Convert.FromBase64String(file64);
File.WriteAllBytes(filepath1, bytes2);
/*End here*/
/*if you need to save this base64 in to database so save this variable value=> file64*/
}
return Request.CreateResponse(HttpStatusCode.OK, file64); ;
}
#endregion
No comments:
Post a Comment