Click here to Skip to main content
15,892,643 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have Developed API Application to use it for Another application and i have an Action to receive image as Base64 and save it on the hard disk.

Here is the link of the realIP of this function - http://84.235.50.145:9111/api/jobs/ImageSender[^]

Here is The API Method i developed
C#
[HttpPost]
[ActionName("ImageSender")]
public void ImgSender(string value)
{
    var base64 = value;

    string ImgPath = LoadImage(base64);
}

public string LoadImage(string img)
{
    byte[] bytes = Convert.FromBase64String(img.Replace(' ', '+'));

    Random Ran = new Random();
    string AddToName = DateTime.Now.Day.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Year.ToString() + Ran.Next(199999);

    try
    {
        System.IO.File.WriteAllBytes(@"F:\EmploymentFiles\img" + AddToName + ".jpg", bytes);

        return @"EmploymentFiles/img" + AddToName + ".jpg";
    }
    catch (Exception ee)

    { return ee.ToString(); }

}

I want to call this function from aspx page and upload the image.

How can I do this in the aspx?


[Edit member="Tadit"]
Added pre tags.
[/Edit]
Posted
v2
Comments
Jameel VM 15-Dec-14 1:47am    
call this service using ajax from aspx page.

1 solution

There are several way, but maybe the most easy to utilize is using jQuery library ajax methods...
http://api.jquery.com/jquery.ajax/[^]
The code should look like this:
JavaScript
$.ajax({
  method: "POST",
  url: "http://84.235.50.145:9111/api/jobs/ImageSender",
  data: base64string,
  dataType: "text"
});
 
Share this answer
 
Comments
Mohammed Elkholy 15-Dec-14 2:36am    
how can i call this function under button using c# code
Kornfeld Eliyahu Peter 15-Dec-14 2:40am    
How c# (server side) code is connected to all this?
Mohammed Elkholy 15-Dec-14 3:30am    
this is what i want to know how can i call this function using c# code

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900