private void button1_Click(object sender, EventArgs e)
{
bool aa = UploadFile(@"D:\ecg_100020200117048.jpg");
MessageBox.Show(aa.ToString());
}
public static bool UploadFile(string filePath)
{
try
{
var fileName = System.IO.Path.GetFileName(filePath);
var client = new RestClient($"{GetPicturesServerBaseUrl()}api/uploadfile");
var request = new RestRequest(Method.POST);
request.AlwaysMultipartFormData = true;
request.AddHeader("Content-Type", "multipart/form-data");
request.AddFile("file", filePath);
request.AddParameter("multipart/form-data", fileName, ParameterType.RequestBody);
var response = client.Execute(request);
return response.StatusCode == System.Net.HttpStatusCode.OK;
}
catch
{
return false;
}
}
public static string GetPicturesServerBaseUrl()
{
return ConfigurationManager.AppSettings["PicturesServerBaseUrl"].Trim();
}