How to upload some files of any type to online ser

2019-07-29 23:50发布

My question resembles a lot of question but I have seen that my question is different. I wanted to apply CRUD operation on file uploading using C#(Windows Form Application). Here is the code I wanted to use...

Code:

async void uploadImage(string url, string api_key, string device_token, string device_type, string email,string file_name)
    {
        IEnumerable<KeyValuePair<string, string>> queries = new List<KeyValuePair<string, string>>()
        {
            new KeyValuePair<string, string>("email",email),
           // new KeyValuePair<string, string>("files",file_name),
            new KeyValuePair<string, string>("api_key",api_key),
            new KeyValuePair<string, string>("device_token",device_token),
            new KeyValuePair<string, string>("device_type",device_type)
        };
        HttpContent q = new FormUrlEncodedContent(queries);
        using (HttpClient client = new HttpClient())
        {
            using (HttpResponseMessage response = await client.PostAsync(url, q))
            {
                using (HttpContent content = response.Content)
                {
                    try
                    {
                        var mycontent = await content.ReadAsStringAsync();
                        var jo = JObject.Parse(mycontent);
                        string errorStatus = jo["Result"]["error"].ToString();
                        string message = jo["Result"]["message"].ToString();
                        if (errorStatus == "False")
                        {
                            MessageBox.Show(message);
                        }
                        else
                        {
                            MessageBox.Show(message);
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
            }
        }
    }

Please help me, how can I do that? Your cooperation will be highly Appreciated

0条回答
登录 后发表回答