public static VideoUploadResponse UploadVideo(byte[] buffer, string extension, string fileName, string uploadDomain) { VideoUploadResponse result = null; try { if (buffer != null && !string.IsNullOrEmpty(extension) && !string.IsNullOrEmpty(fileName) && !string.IsNullOrEmpty(uploadDomain)) { using (var client = new FileUploadClient()) { var getResult = client.UploadVideo(new FileUploadRequest() { Contents = buffer, DirectoryName = uploadDomain, Extension = extension }); getResult.ThrowIfException(true); if (getResult.Success && getResult.Exception == null) { result = getResult.Result; buffer = null; } } } } catch (Exception ex) { logger.Error(ex); } return(result); }
/// <summary> /// Upload Video api call /// </summary> /// <param name="url"> upload url created by CreateVideoUploadUrl() method</param> /// <param name="filePath"> physical file path of the video</param> /// <returns></returns> public VideoUploadResponse UploadVideo(string filePath) { VideoUploadResponse response = new VideoUploadResponse(); response.Status = CallExecutionStatus.Error; try { //create upload url UploadUrl url = CreateVideoUploadUrl(); //format upload url string upload_url = url.Link.Protocol + "://" + url.Link.Address + url.Link.Path; string uploadResponse = ""; //create request query strings parameters NameValueCollection nvc = new NameValueCollection(); nvc.Add("key", url.Link.Query.Key); nvc.Add("token", url.Link.Query.Token); uploadResponse = Upload(upload_url, nvc, filePath); //deserialize response to VideoUploadResponse response = JsonConvert.DeserializeObject <VideoUploadResponse>(uploadResponse); //set api call result response.ErrorMessage = ""; response.Status = CallExecutionStatus.OK; } catch (Exception ex) { response.Status = CallExecutionStatus.Error; response.ErrorMessage = ex.Message + Environment.NewLine + ex.StackTrace; } return(response); }
public async Task <IActionResult> Video([FromForm] VideoUploadRequest videoUploadRequest) { _logger.LogInformation("Starting upload..."); try { var result = await _azureStreamingService.UploadFileAsync(videoUploadRequest); return(new VideoResponse( VideoUploadResponse.CreateInstanceFromAsset(result), StatusCodes.Status200OK)); } catch (Exception exception) { _logger.LogError("Error uploading", exception); var error = VideoResultError.CreateInstance( "An error has occured attempting to upload the video.", HttpContext, ErrorType.InternalServer); return(new VideoResponse(error, StatusCodes.Status422UnprocessableEntity)); } }