I have the connection working between my WP8 and WFC, I can send a picture as stream(byte-array)
Service side
[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "FileUpload/{fileName}")]
string SendImageToDB(string fileName, Stream fileStream);
SendImageToDB
public void SendSteamToDB(byte[] stream)
{
MySqlConnection connection = new MySqlConnection(MyconSQL);
MySqlCommand cmd;
connection.Open();
try
{
cmd = connection.CreateCommand();
cmd.CommandText = "UPDATE PIC SET pic_link=@image WHERE id = '1';";
cmd.Parameters.Add("@image", MySqlDbType.Blob).Value = stream;
cmd.ExecuteNonQuery();
}
catch (MySqlException ex)
{
Console.Write("Error: {0}", ex.ToString());
}
finally
{
if (connection != null)
{
connection.Close();
}
}
}
The windows phone side
private void Upload_Click(object sender, EventArgs e)
{
string imageID = "test";
var client = new RestClient("http://192.168.1.130:53715//Service1.svc");
var request = new RestRequest("FileUpload/{imageName}", Method.POST);
request.AddUrlSegment("imageName", imageID);
request.AddFile("image/jpeg", myImage, imageID);
client.ExecuteAsync(request, response =>
{
});
try
{
client.ExecuteAsync(request, response =>
{
if (response.StatusCode == HttpStatusCode.OK)
{
MessageBox.Show("Upload succes!");
}
else
{
MessageBox.Show(response.StatusCode.ToString());
MessageBox.Show("Upload error!");
}
});
}
catch (Exception error)
{
MessageBox.Show("error" + error);
}
}
All this is working fine, there is just one problem the byte-array I put into the database have some kind of 'header'
did put the byte array in a .txt
What is the best way to avoid this?