示例#1
0
        /// <summary>
        /// Used to upload new video.
        /// Vippy endpoint: PUT http://rest.vippy.co/video
        /// </summary>
        /// <param name="newVideoRequest"><see cref="NewVideoRequest"/></param>
        /// <returns>Video <see cref="Video"/></returns>
        // TODO: create strongly typed return type 
        public async Task<dynamic> PutVideo(NewVideoRequest newVideoRequest)
        {
            var client = this.GetHttpClient();

            var dataContent = new ByteArrayContent(newVideoRequest.Data);
            dataContent.Headers.ContentType = MediaTypeHeaderValue.Parse(newVideoRequest.ContentType);
            client.DefaultRequestHeaders.Add("x-vpy-video", newVideoRequest.VideoPath);
            client.DefaultRequestHeaders.Add("x-vpy-title", newVideoRequest.Title);
            client.DefaultRequestHeaders.Authorization = this.GenerateAuthorizationHeader(client, dataContent.Headers);

            var response = await client.PutAsync("/video", dataContent).ConfigureAwait(false);

            response.EnsureSuccessStatusCode();
            var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

            return JsonConvert.DeserializeObject<dynamic>(responseContent);
        }
示例#2
0
文件: VideoFile.cs 项目: Geta/vippy
        private Stream UploadVideo()
        {
            var file = HttpContext.Current.Request.Files[0];
            var fileStream = file.InputStream;
            var contentType = file.ContentType;
            var filename = file.FileName;
            long contentLength;

            byte[] data;
            using (var memoryStream = new MemoryStream())
            {
                fileStream.Position = 0;
                fileStream.CopyTo(memoryStream);
                contentLength = memoryStream.Length;
                data = memoryStream.ToArray();
            }

            var newVideoRequest = new NewVideoRequest
            {
                Data = data,
                ContentLength = contentLength,
                Title = Path.GetFileNameWithoutExtension(filename),
                VideoPath = filename,
                ContentType = contentType
            };

            var response = _provider.VippyClient.PutVideo(newVideoRequest).Result;

            return new MemoryStream();
        }