Пример #1
0
        public static async Task <string> UploadUserResponse(string videoId, byte[] uploadFileBinary,
                                                             InputSelectedType selectedType, string Description, string thumbNail = null)
        {
            string msg = string.Empty;

            try
            {
                using (var client = new HttpClient())
                {
                    using (var content = new MultipartFormDataContent())
                    {
                        var values = new[]
                        {
                            new KeyValuePair <string, string>("video_id", videoId),
                            new KeyValuePair <string, string>("session_id", UserDetails.AccessToken),
                            new KeyValuePair <string, string>("inputType", selectedType == InputSelectedType.Selected ? "uploaded-video" : "recorded-video"),
                            new KeyValuePair <string, string>("description", Description)
                        };
                        foreach (var keyValuePair in values)
                        {
                            content.Add(new StringContent(keyValuePair.Value), keyValuePair.Key);
                        }
                        var fileContent = new StreamContent(new MemoryStream(uploadFileBinary));
                        fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
                        {
                            Name     = selectedType == InputSelectedType.Selected ? "uploadedVideo": "recordedVideo",
                            FileName = "test.mp4"
                        };
                        fileContent.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
                        content.Add(fileContent, selectedType == InputSelectedType.Selected ? "uploadedVideo" : "recordedVideo");
                        client.Timeout = Timeout.InfiniteTimeSpan;
                        var result = await client.PostAsync(UserResponseURL.UploadVideoResponseURL, content);

                        var response = await result.Content.ReadAsStringAsync();

                        var responseModel = JsonConvert.DeserializeObject <ResponseModel>(response);
                        msg = responseModel.msg;
                    }
                }
            }
            catch (Exception ex)
            {
                msg = "Something went wrong, please try again later";
            }
            return(msg);
        }
Пример #2
0
        public static async Task <string> UploadAudioUserResponse(string videoId, byte[] uploadFileBinary,
                                                                  InputSelectedType selectedType, string Description, string thumbNail = null)
        {
            string msg = string.Empty;

            try
            {
                var filename = "test.mp3";
                var client   = new RestClient(UserResponseURL.UploadAudioResponseURL);
                client.Timeout = -1;
                var request = new RestRequest(Method.POST);
                request.AddParameter("video_id", videoId);
                request.AddParameter("session_id", UserDetails.AccessToken);
                request.AddParameter("description", Description);
                request.AddFileBytes("audio", uploadFileBinary, filename, "application/octet-stream");
                if (selectedType == InputSelectedType.Selected)
                {
                    request.AddParameter("inputType", "uploaded-audio");
                }
                else
                {
                    request.AddParameter("inputType", "recorded-audio");
                }
                IRestResponse response = await client.ExecuteAsync(request);

                var responseModel = JsonConvert.DeserializeObject <ResponseModel>(response.Content);
                if (responseModel != null)
                {
                    msg = responseModel.msg;
                }
            }
            catch (Exception ex)
            {
                msg = "Something went wrong, please try again later";
            }
            return(msg);
        }