src/Classificationbox.Net/ServiceWrapper.cs
/// <summary>
/// Loads the saved model from the specified file into the classificationbox
/// </summary>
/// <param name="filename">filename of the saved model</param>
/// <returns>OK for success or error message</returns>
Loads the saved model from the specified file into the classificationbox
Loads the saved model from the specified file into the classificationbox
public string LoadModel(string filename)
        {
            Byte[] bytes = File.ReadAllBytes(filename);
            String base64 = Convert.ToBase64String(bytes);
            using (HttpClient client = new HttpClient())
            {
                var byteContent = new ByteArrayContent(bytes);
                var content = new MultipartFormDataContent();
                content.Add(byteContent, "file", filename);
                var request = new HttpRequestMessage
                {
                    Method = HttpMethod.Post,
                    RequestUri = new Uri(string.Format("{0}/classificationbox/state", _baseUrl)),
                    Headers = {
                        { HttpRequestHeader.Accept.ToString(), "application/json; charset=utf-8" }
                    },
                    Content = content
                };
                HttpResponseMessage rsp;
                try
                {
                    rsp = client.SendAsync(request).GetAwaiter().GetResult();
                }
                catch (Exception ex)
                {
                    return ex.Message;
                }
                if (rsp.IsSuccessStatusCode)
                {
                    var s = rsp.Content.ReadAsStringAsync().Result;
                    return "OK";
                }
                else
                {
                    var s = rsp.Content.ReadAsStringAsync().Result;
                    return s;
                }
            }
        }
public string LoadModel ( string filename ) { Byte [ ] bytes = File . ReadAllBytes ( filename ) ; String base64 = Convert . ToBase64String ( bytes ) ; using ( HttpClient client = new HttpClient ( ) ) { var byteContent = new ByteArrayContent ( bytes ) ; var content = new MultipartFormDataContent ( ) ; content . Add ( byteContent , " " , filename ) ; var request = new HttpRequestMessage { Method = HttpMethod . Post , RequestUri = new Uri ( string . Format ( " " , _baseUrl ) ) , Headers = { { HttpRequestHeader . Accept . ToString ( ) , " " } } , Content = content } ; HttpResponseMessage rsp ; try { rsp = client . SendAsync ( request ) . GetAwaiter ( ) . GetResult ( ) ; } catch ( Exception ex ) { return ex . Message ; } if ( rsp . IsSuccessStatusCode ) { var s = rsp . Content . ReadAsStringAsync ( ) . Result ; return " " ; } else { var s = rsp . Content . ReadAsStringAsync ( ) . Result ; return s ; } } }
Loads the saved model from the specified file into the classificationbox
Loads the saved model from the specified file into the classificationbox
//var payload = string.Format("base64={0}", base64); //HttpContent content = new FormUrlEncodedContent(new KeyValuePair<string,string>("base64", byteContent.)); //var payload = string.Format("base64={0}", base64); //HttpContent content = new StringContent(payload, Encoding.UTF8, "application/x-www-form-urlencoded"); //var request = new HttpRequestMessage //{ //    Method = HttpMethod.Post, //    RequestUri = new Uri(string.Format("{0}/classificationbox/state", _baseUrl)), //    Headers = { //        { HttpRequestHeader.Accept.ToString(), "application/json; charset=utf-8" } //    }, //    Content = content //};
OK for success or error message
OK for success or error message
filename
string
filename of the saved model
filename of the saved model