I would like to ask how to upload image from Windows phone 8.1. My solution is with Base64 decode, but I think, that this is not the best way...
In my Windows Phone 8.1 app I select the image and after select I decode image to base64. My idea was that I send this base64 string to my WebServise as parameter like this
www.myservice.com/ImageUpload.aspx?img=myBase64String
and decode it on server back to the image file and upload to server.
BUT this base64 string is too long so webservice returning error "The request URL is too long."
So is another way to upload image file to web from Windows Phone 8.1
And which is better. Save image to database as base64 string or as BLOB. Thanks
EDIT:
Request in Windows phone :
public async Task<string> ImageToBase64(StorageFile MyImageFile)
{
Stream ms = await MyImageFile.OpenStreamForReadAsync();
byte[] imageBytes = new byte[(int)ms.Length];
ms.Read(imageBytes, 0, (int)ms.Length);
string base64Image = Convert.ToBase64String(imageBytes);
string url = "http://mobil.aspone.com/ImageUpload.aspx?Id=" + base64Image;
HttpClient client = new HttpClient();
var response = await client.GetAsync(new Uri(url));
var result = await response.Content.ReadAsStringAsync();
string jsonString = result.ToString();
return jsonString;
}
ASP.NET service
protected void Page_Load(object sender, EventArgs e)
{
string Id = Request.QueryString["Id"];
//byte[] bytes = Convert.FromBase64String(Id);
Image1.ImageUrl = "data:image/png;base64," + Id;
If(Id!=null)
{
Response.Clear();
Response.ContentType = "application/json; charset=utf-8";
Response.Write("Uploaded");
Response.End();
}
else
{
Response.Clear();
Response.ContentType = "application/json; charset=utf-8";
Response.Write("Failed");
Response.End();
}