コード例 #1
0
        /// <inheritdoc />
        public async Task <TextTrack> UploadTextTrackFileAsync(IBinaryContent fileContent, long videoId, TextTrack track)
        {
            if (!fileContent.Data.CanRead)
            {
                throw new ArgumentException("fileContent should be readable");
            }

            if (fileContent.Data.CanSeek && fileContent.Data.Position > 0)
            {
                fileContent.Data.Position = 0;
            }

            var ticket = await GetUploadTextTrackTicketAsync(videoId, track).ConfigureAwait(false);

            var request = _apiRequestFactory.GetApiRequest();

            request.Method = HttpMethod.Put;
            request.ExcludeAuthorizationHeader = true;
            request.Path = ticket.Link;

            request.Body = new ByteArrayContent(await fileContent.ReadAllAsync().ConfigureAwait(false));

            var response = await request.ExecuteRequestAsync().ConfigureAwait(false);

            CheckStatusCodeError(null, response, "Error uploading text track file.", HttpStatusCode.BadRequest);

            return(ticket);
        }
コード例 #2
0
        /// <summary>
        /// Upload new text track file asynchronously
        /// </summary>
        /// <param name="fileContent">File content</param>
        /// <param name="videoId">VideoId</param>
        /// <param name="track">Track</param>
        /// <returns>New text track</returns>
        public async Task <TextTrack> UploadTextTrackFileAsync(IBinaryContent fileContent, long videoId, TextTrack track)
        {
            if (!fileContent.Data.CanRead)
            {
                throw new ArgumentException("fileContent should be readable");
            }
            if (fileContent.Data.CanSeek && fileContent.Data.Position > 0)
            {
                fileContent.Data.Position = 0;
            }

            TextTrack ticket = await GetUploadTextTrackTicketAsync(videoId, track);

            IApiRequest request = ApiRequestFactory.GetApiRequest();

            request.Method = Method.PUT;
            request.ExcludeAuthorizationHeader = true;
            request.Path = ticket.link;
            request.Headers.Add(Request.HeaderContentType, fileContent.ContentType);
            request.Headers.Add(Request.HeaderContentLength, fileContent.Data.Length.ToString());
            request.BinaryContent = await fileContent.ReadAllAsync();

            IRestResponse response = await request.ExecuteRequestAsync();

            CheckStatusCodeError(null, response, "Error uploading text track file.", HttpStatusCode.BadRequest);

            return(ticket);
        }
コード例 #3
0
        public async Task <IUploadRequest> StartUploadFileAsync(IBinaryContent fileContent,
                                                                int chunkSize       = DEFAULT_UPLOAD_CHUNK_SIZE,
                                                                long?replaceVideoId = null)
        {
            if (!fileContent.Data.CanRead)
            {
                throw new ArgumentException("fileContent should be readable");
            }
            if (fileContent.Data.CanSeek && fileContent.Data.Position > 0)
            {
                fileContent.Data.Position = 0;
            }

            UploadTicket ticket = replaceVideoId.HasValue
                ? await GetReplaceVideoUploadTicketAsync(replaceVideoId.Value)
                : await GetUploadTicketAsync();

            var uploadRequest = new UploadRequest
            {
                Ticket    = ticket,
                File      = fileContent,
                ChunkSize = chunkSize
            };

            VerifyUploadResponse uploadStatus = await ContinueUploadFileAsync(uploadRequest);

            return(uploadRequest);
        }
コード例 #4
0
        /// <summary>
        /// upload picture asynchronously
        /// </summary>
        /// <param name="fileContent">fileContent</param>
        /// <returns>upload pic </returns>
        public async Task <Picture> UploadPictureAsync(IBinaryContent fileContent, long clipId)
        {
            try
            {
                if (!fileContent.Data.CanRead)
                {
                    throw new ArgumentException("fileContent should be readable");
                }
                if (fileContent.Data.CanSeek && fileContent.Data.Position > 0)
                {
                    fileContent.Data.Position = 0;
                }
                ThrowIfUnauthorized();
                var request = ApiRequestFactory.GetApiRequest(AccessToken);
                request.Method = HttpMethod.Post;
                request.Path   = Endpoints.Pictures;
                request.UrlSegments.Add("clipId", clipId.ToString());

                request.Body = new ByteArrayContent(await fileContent.ReadAllAsync());

                var response = await request.ExecuteRequestAsync <Picture>();

                CheckStatusCodeError(null, response, "Error generating upload ticket to replace video.");

                return(response.Content);
            }
            catch (Exception ex)
            {
                if (ex is VimeoApiException)
                {
                    throw;
                }
                throw new VimeoUploadException("Error Uploading picture.", null, ex);
            }
        }
コード例 #5
0
        public async Task <IUploadRequest> StartUploadFileAsync(IBinaryContent fileContent,
                                                                int chunkSize = DEFAULT_UPLOAD_CHUNK_SIZE)
        {
            if (!fileContent.Data.CanRead)
            {
                throw new ArgumentException("fileContent should be readable");
            }
            if (fileContent.Data.CanSeek && fileContent.Data.Position > 0)
            {
                fileContent.Data.Position = 0;
            }

            UploadTicket ticket = await GetUploadTicketAsync();

            var uploadRequest = new UploadRequest
            {
                Ticket    = ticket,
                File      = fileContent,
                ChunkSize = chunkSize
            };

            VerifyUploadResponse uploadStatus = await ContinueUploadFileAsync(uploadRequest);

            uploadRequest.BytesWritten = uploadStatus.BytesWritten;

            return(uploadRequest);
        }
コード例 #6
0
        /// <summary>
        /// Start upload file asynchronously
        /// </summary>
        /// <param name="fileContent">FileContent</param>
        /// <param name="chunkSize">ChunkSize</param>
        /// <param name="replaceVideoId">ReplaceVideoId</param>
        /// <returns></returns>
        private async Task <IUploadRequest> StartUploadFileAsync(IBinaryContent fileContent,
                                                                 int chunkSize       = DefaultUploadChunkSize,
                                                                 long?replaceVideoId = null)
        {
            if (!fileContent.Data.CanRead)
            {
                throw new ArgumentException("fileContent should be readable");
            }

            if (fileContent.Data.CanSeek && fileContent.Data.Position > 0)
            {
                fileContent.Data.Position = 0;
            }

            var ticket = replaceVideoId.HasValue
                ? await GetReplaceVideoUploadTicketAsync(replaceVideoId.Value).ConfigureAwait(false)
                : await GetUploadTicketAsync().ConfigureAwait(false);

            var uploadRequest = new UploadRequest
            {
                Ticket    = ticket,
                File      = fileContent,
                ChunkSize = chunkSize
            };

            return(uploadRequest);
        }
コード例 #7
0
        static public async Task <AES256WithKey> Encrypt(IContentContext context, IBinaryContent keyData, Content content)
        {
            var result = new AES256WithKey()
            {
                Key = keyData
            };
            await result.Create(await keyData.GetBinContent(context), content.Serialize());

            return(result);
        }
コード例 #8
0
 public IUploadRequest UploadEntireFile(IBinaryContent fileContent, int chunkSize = DEFAULT_UPLOAD_CHUNK_SIZE, long?replaceVideoId = null)
 {
     try
     {
         return(UploadEntireFileAsync(fileContent, chunkSize, replaceVideoId).RunSynchronouslyWithCurrentCulture());
     }
     catch (AggregateException ex)
     {
         ExceptionDispatchInfo.Capture(ex.InnerException).Throw();
     }
     return(null);
 }
コード例 #9
0
 public IUploadRequest UploadEntireFile(IBinaryContent fileContent, int chunkSize = DEFAULT_UPLOAD_CHUNK_SIZE)
 {
     try
     {
         return(Task.Run(async() => await UploadEntireFileAsync(fileContent, chunkSize)).Result);
     }
     catch (AggregateException ex)
     {
         ExceptionDispatchInfo.Capture(ex.InnerException).Throw();
         return(null);
     }
 }
コード例 #10
0
 public IUploadRequest StartUploadFile(IBinaryContent fileContent, int chunkSize = DEFAULT_UPLOAD_CHUNK_SIZE)
 {
     try
     {
         return(StartUploadFileAsync(fileContent, chunkSize).RunSynchronouslyWithCurrentCulture());
     }
     catch (AggregateException ex)
     {
         ExceptionDispatchInfo.Capture(ex.InnerException).Throw();
         return(null);
     }
 }
コード例 #11
0
 public Picture UploadThumbnail(long clipId, IBinaryContent fileContent)
 {
     try
     {
         var pic = UploadPictureAsync(fileContent, clipId).RunSynchronouslyWithCurrentCulture();
         SetThumbnailActiveAsync(pic.uri).RunSynchronouslyWithCurrentCulture();
         return(pic);
     }
     catch (AggregateException ex)
     {
         ExceptionDispatchInfo.Capture(ex.InnerException).Throw();
         return(null);
     }
 }
コード例 #12
0
        private async Task <IApiRequest> GenerateFileStreamRequest(IBinaryContent fileContent, UploadTicket ticket,
                                                                   long written = 0, int?chunkSize = null, bool verifyOnly = false)
        {
            if (string.IsNullOrWhiteSpace(ticket?.TicketId))
            {
                throw new ArgumentException("Invalid upload ticket.");
            }

            if (fileContent.Data.Length > ticket.User.UploadQuota.Space.Free)
            {
                throw new InvalidOperationException(
                          "User does not have enough free space to upload this video. Remaining space: " +
                          ticket.Quota.FreeSpace + ".");
            }

            var request = _apiRequestFactory.GetApiRequest();

            request.Method = HttpMethod.Put;
            request.ExcludeAuthorizationHeader = true;
            request.Path = ticket.UploadLinkSecure;

            if (verifyOnly)
            {
                var body = new ByteArrayContent(new byte[0]);
                body.Headers.Add("Content-Range", "bytes */*");
                body.Headers.ContentLength = 0;
                request.Body = body;
            }
            else
            {
                if (chunkSize.HasValue)
                {
                    var startIndex = fileContent.Data.CanSeek ? fileContent.Data.Position : written;
                    var endIndex   = Math.Min(startIndex + chunkSize.Value, fileContent.Data.Length);
                    var byteArray  = await fileContent.ReadAsync(startIndex, endIndex).ConfigureAwait(false);

                    var body = new ByteArrayContent(byteArray, 0, byteArray.Length);
                    body.Headers.Add("Content-Range", $"bytes {startIndex}-{endIndex}/*");
                    body.Headers.ContentLength = endIndex - startIndex;
                    request.Body = body;
                }
                else
                {
                    request.Body = new ByteArrayContent(await fileContent.ReadAllAsync().ConfigureAwait(false));
                }
            }

            return(request);
        }
コード例 #13
0
        private async Task <IApiRequest> GenerateFileStreamRequest(IBinaryContent fileContent, UploadTicket ticket,
                                                                   long written = 0, int?chunkSize = null, bool verifyOnly = false)
        {
            if (ticket == null || string.IsNullOrWhiteSpace(ticket.ticket_id))
            {
                throw new ArgumentException("Invalid upload ticket.");
            }
            if (fileContent.Data.Length > ticket.user.upload_quota.space.free)
            {
                throw new InvalidOperationException(
                          "User does not have enough free space to upload this video. Remaining space: " +
                          ticket.quota.free_space + ".");
            }

            IApiRequest request = _apiRequestFactory.GetApiRequest();

            request.Method = Method.PUT;
            request.ExcludeAuthorizationHeader = true;
            request.Path = ticket.upload_link_secure;
            request.Headers.Add(Request.HeaderContentType, fileContent.ContentType);
            if (verifyOnly)
            {
                request.Headers.Add(Request.HeaderContentLength, "0");
                request.Headers.Add(Request.HeaderContentRange, "bytes */*");
            }
            else
            {
                if (chunkSize.HasValue)
                {
                    long startIndex = fileContent.Data.CanSeek ? fileContent.Data.Position : written;
                    long endIndex   = Math.Min(startIndex + chunkSize.Value, fileContent.Data.Length);
                    request.Headers.Add(Request.HeaderContentLength, (endIndex - startIndex).ToString());
                    request.Headers.Add(Request.HeaderContentRange,
                                        string.Format("bytes {0}-{1}/{2}", startIndex, endIndex, fileContent.Data.Length));
                    request.BinaryContent = await fileContent.ReadAsync(startIndex, endIndex);
                }
                else
                {
                    request.Headers.Add(Request.HeaderContentLength, fileContent.Data.Length.ToString());
                    request.BinaryContent = await fileContent.ReadAllAsync();
                }
            }

            return(request);
        }
コード例 #14
0
ファイル: VimeoClient_Upload.cs プロジェクト: r15h1/heyteam
        /// <summary>
        /// Upload and set thumbnail active
        /// </summary>
        /// <param name="clipId"></param>
        /// <param name="fileContent"></param>
        /// <returns></returns>
        /// <exception cref="VimeoUploadException"></exception>
        public async Task <Picture> UploadThumbnailAsync(long clipId, IBinaryContent fileContent)
        {
            try
            {
                var pic = await UploadPictureAsync(fileContent, clipId);
                await SetThumbnailActiveAsync(pic.uri);

                return(pic);
            }
            catch (Exception ex)
            {
                if (ex is VimeoApiException)
                {
                    throw;
                }
                throw new VimeoUploadException("Error generating upload ticket.", null, ex);
            }
        }
コード例 #15
0
        public async Task <IUploadRequest> UploadEntireFileAsync(IBinaryContent fileContent,
                                                                 int chunkSize       = DEFAULT_UPLOAD_CHUNK_SIZE,
                                                                 long?replaceVideoId = null)
        {
            IUploadRequest uploadRequest = await StartUploadFileAsync(fileContent, chunkSize, replaceVideoId);

            VerifyUploadResponse uploadStatus = null;

            while (!uploadRequest.IsVerifiedComplete)
            {
                uploadStatus = await ContinueUploadFileAsync(uploadRequest);

                if (uploadRequest.AllBytesWritten)
                {
                    // We presumably wrote all the bytes in the file, so verify with Vimeo that it
                    // is completed
                    uploadStatus = await VerifyUploadFileAsync(uploadRequest);

                    if (uploadStatus.Status == UploadStatusEnum.Completed)
                    {
                        // If completed, mark file as complete
                        await CompleteFileUploadAsync(uploadRequest);

                        uploadRequest.IsVerifiedComplete = true;
                    }
                    else if (uploadStatus.BytesWritten == uploadRequest.FileLength)
                    {
                        // Supposedly all bytes are written, but Vimeo doesn't think so, so just
                        // bail out
                        throw new VimeoUploadException(
                                  string.Format(
                                      "Vimeo failed to mark file as completed, Bytes Written: {0:N0}, Expected: {1:N0}.",
                                      uploadStatus.BytesWritten),
                                  uploadRequest);
                    }
                }
            }

            return(uploadRequest);
        }
コード例 #16
0
        private async Task <IApiRequest> GenerateFileStreamRequest(IBinaryContent fileContent, UploadTicket ticket,
                                                                   long written = 0, int?chunkSize = null, bool verifyOnly = false)
        {
            if (ticket == null || string.IsNullOrWhiteSpace(ticket.ticket_id))
            {
                throw new ArgumentException("Invalid upload ticket.");
            }
            if (fileContent.Data.Length > ticket.user.upload_quota.space.free)
            {
                throw new InvalidOperationException(
                          "User does not have enough free space to upload this video. Remaining space: " +
                          ticket.quota.free_space + ".");
            }

            var request = ApiRequestFactory.GetApiRequest();

            request.Method = HttpMethod.Put;
            request.ExcludeAuthorizationHeader = true;
            request.Path = ticket.upload_link_secure;

            if (verifyOnly)
            {
                request.Body = new ByteArrayContent(new byte [0]);
            }
            else
            {
                if (chunkSize.HasValue)
                {
                    var startIndex = fileContent.Data.CanSeek ? fileContent.Data.Position : written;
                    var endIndex   = Math.Min(startIndex + chunkSize.Value, fileContent.Data.Length);
                    request.Body = new ByteArrayContent(await fileContent.ReadAsync(startIndex, endIndex), (int)startIndex, (int)endIndex);
                }
                else
                {
                    request.Body = new ByteArrayContent(await fileContent.ReadAllAsync());
                }
            }

            return(request);
        }
コード例 #17
0
        /// <inheritdoc />
        public async Task <IUploadRequest> UploadEntireFileAsync(IBinaryContent fileContent,
                                                                 int chunkSize                  = DefaultUploadChunkSize,
                                                                 long?replaceVideoId            = null,
                                                                 Action <double> statusCallback = null)
        {
            var uploadRequest = await StartUploadFileAsync(fileContent, chunkSize, replaceVideoId).ConfigureAwait(false);

            while (!uploadRequest.IsVerifiedComplete)
            {
                var uploadStatus = await ContinueUploadFileAsync(uploadRequest).ConfigureAwait(false);

                statusCallback?.Invoke(Math.Round(((double)uploadStatus.BytesWritten / uploadRequest.FileLength) * 100));

                if (uploadStatus.Status == UploadStatusEnum.InProgress)
                {
                    continue;
                }
                // We presumably wrote all the bytes in the file, so verify with Vimeo that it
                // is completed
                uploadStatus = await VerifyUploadFileAsync(uploadRequest).ConfigureAwait(false);

                if (uploadStatus.Status == UploadStatusEnum.Completed)
                {
                    // If completed, mark file as complete
                    await CompleteFileUploadAsync(uploadRequest).ConfigureAwait(false);

                    uploadRequest.IsVerifiedComplete = true;
                }
                else if (uploadStatus.BytesWritten == uploadRequest.FileLength)
                {
                    // Supposedly all bytes are written, but Vimeo doesn't think so, so just
                    // bail out
                    throw new VimeoUploadException(
                              $"Vimeo failed to mark file as completed, Bytes Written: {uploadStatus.BytesWritten:N0}, Expected: {uploadRequest.FileLength:N0}.",
                              uploadRequest);
                }
            }

            return(uploadRequest);
        }
コード例 #18
0
        /// <summary>
        /// upload picture asynchronously
        /// </summary>
        /// <param name="fileContent">fileContent</param>
        /// <param name="link">link</param>
        /// <returns>upload pic </returns>
        public async Task UploadPictureAsync(IBinaryContent fileContent, string link)
        {
            try
            {
                if (!fileContent.Data.CanRead)
                {
                    throw new ArgumentException("fileContent should be readable");
                }
                if (fileContent.Data.CanSeek && fileContent.Data.Position > 0)
                {
                    fileContent.Data.Position = 0;
                }
                ThrowIfUnauthorized();
                var request = ApiRequestFactory.GetApiRequest(AccessToken);
                request.Method = HttpMethod.Put;
                request.Path   = link;
                //request.Header.Add(Request.HeaderContentType, "image/jpeg");
                //request.Headers.Add(Request.HeaderContentLength, fileContent.Data.Length.ToString());

                request.Body = new ByteArrayContent(await fileContent.ReadAllAsync());

                var response = await request.ExecuteRequestAsync();

                CheckStatusCodeError(null, response, "Error generating upload ticket to replace video.");

                //return response.Data;
            }
            catch (Exception ex)
            {
                if (ex is VimeoApiException)
                {
                    throw;
                }
                throw new VimeoUploadException("Error Uploading picture.", null, ex);
            }
        }
コード例 #19
0
 public IUploadRequest UploadEntireFile(IBinaryContent fileContent, int chunkSize = DEFAULT_UPLOAD_CHUNK_SIZE)
 {
     try
     {
         return UploadEntireFileAsync(fileContent, chunkSize).RunSynchronouslyWithCurrentCulture();
     }
     catch (AggregateException ex)
     {
         ExceptionDispatchInfo.Capture(ex.InnerException).Throw();
         return null;
     }
 }
コード例 #20
0
 public IUploadRequest UploadEntireFile(IBinaryContent fileContent, int chunkSize = DEFAULT_UPLOAD_CHUNK_SIZE)
 {
     try
     {
         return Task.Run(async () => await UploadEntireFileAsync(fileContent, chunkSize)).Result;
     }
     catch (AggregateException ex)
     {
         ExceptionDispatchInfo.Capture(ex.InnerException).Throw();
         return null;
     }
 }
コード例 #21
0
        private async Task<IApiRequest> GenerateFileStreamRequest(IBinaryContent fileContent, UploadTicket ticket,
            long written = 0, int? chunkSize = null, bool verifyOnly = false)
        {
            if (ticket == null || string.IsNullOrWhiteSpace(ticket.ticket_id))
            {
                throw new ArgumentException("Invalid upload ticket.");
            }
            if (fileContent.Data.Length > ticket.user.upload_quota.space.free)
            {
                throw new InvalidOperationException(
                    "User does not have enough free space to upload this video. Remaining space: " +
                    ticket.quota.free_space + ".");
            }

            IApiRequest request = _apiRequestFactory.GetApiRequest();
            request.Method = Method.PUT;
            request.ExcludeAuthorizationHeader = true;
            request.Path = ticket.upload_link_secure;
            request.Headers.Add(Request.HeaderContentType, fileContent.ContentType);
            if (verifyOnly)
            {
                request.Headers.Add(Request.HeaderContentLength, "0");
                request.Headers.Add(Request.HeaderContentRange, "bytes */*");
            }
            else
            {
                if (chunkSize.HasValue)
                {
                    long startIndex = fileContent.Data.CanSeek ? fileContent.Data.Position : written;
                    long endIndex = Math.Min(startIndex + chunkSize.Value, fileContent.Data.Length);
                    request.Headers.Add(Request.HeaderContentLength, (endIndex - startIndex).ToString());
                    request.Headers.Add(Request.HeaderContentRange,
                        string.Format("bytes {0}-{1}/{2}", startIndex, endIndex, fileContent.Data.Length));
                    request.BinaryContent = await fileContent.ReadAsync(startIndex, endIndex);
                }
                else
                {
                    request.Headers.Add(Request.HeaderContentLength, fileContent.Data.Length.ToString());
                    request.BinaryContent = await fileContent.ReadAllAsync();
                }
            }

            return request;
        }
コード例 #22
0
        public async Task<IUploadRequest> UploadEntireFileAsync(IBinaryContent fileContent,
            int chunkSize = DEFAULT_UPLOAD_CHUNK_SIZE,
            long? replaceVideoId = null)
        {
            IUploadRequest uploadRequest = await StartUploadFileAsync(fileContent, chunkSize, replaceVideoId);

            VerifyUploadResponse uploadStatus = null;
            while (!uploadRequest.IsVerifiedComplete)
            {
                uploadStatus = await ContinueUploadFileAsync(uploadRequest);                

                if (uploadRequest.AllBytesWritten)
                {
                    // We presumably wrote all the bytes in the file, so verify with Vimeo that it
                    // is completed
                    uploadStatus = await VerifyUploadFileAsync(uploadRequest);
                    if (uploadStatus.Status == UploadStatusEnum.Completed)
                    {
                        // If completed, mark file as complete
                        await CompleteFileUploadAsync(uploadRequest);
                        uploadRequest.IsVerifiedComplete = true;
                    }
                    else if (uploadStatus.BytesWritten == uploadRequest.FileLength)
                    {
                        // Supposedly all bytes are written, but Vimeo doesn't think so, so just
                        // bail out
                        throw new VimeoUploadException(
                            string.Format(
                                "Vimeo failed to mark file as completed, Bytes Written: {0:N0}, Expected: {1:N0}.",
                                uploadStatus.BytesWritten),
                            uploadRequest);
                    }
                }
            }

            return uploadRequest;
        }
コード例 #23
0
        public async Task<IUploadRequest> StartUploadFileAsync(IBinaryContent fileContent,
            int chunkSize = DEFAULT_UPLOAD_CHUNK_SIZE,
            long? replaceVideoId = null)
        {
            if (!fileContent.Data.CanRead)
            {
                throw new ArgumentException("fileContent should be readable");
            }
            if (fileContent.Data.CanSeek && fileContent.Data.Position > 0)
            {
                fileContent.Data.Position = 0;
            }

            UploadTicket ticket = replaceVideoId.HasValue 
                ? await GetReplaceVideoUploadTicketAsync(replaceVideoId.Value)
                : await GetUploadTicketAsync();

            var uploadRequest = new UploadRequest
            {
                Ticket = ticket,
                File = fileContent,
                ChunkSize = chunkSize
            };

            VerifyUploadResponse uploadStatus = await ContinueUploadFileAsync(uploadRequest);
            
            return uploadRequest;
        }
コード例 #24
0
        public async Task<IUploadRequest> StartUploadFileAsync(IBinaryContent fileContent,
            int chunkSize = DEFAULT_UPLOAD_CHUNK_SIZE)
        {
            if (!fileContent.Data.CanRead)
            {
                throw new ArgumentException("fileContent should be readable");
            }
            if (fileContent.Data.CanSeek && fileContent.Data.Position > 0)
            {
                fileContent.Data.Position = 0;
            }

            UploadTicket ticket = await GetUploadTicketAsync();

            var uploadRequest = new UploadRequest
            {
                Ticket = ticket,
                File = fileContent,
                ChunkSize = chunkSize
            };

            VerifyUploadResponse uploadStatus = await ContinueUploadFileAsync(uploadRequest);
            uploadRequest.BytesWritten = uploadStatus.BytesWritten;

            return uploadRequest;
        }
コード例 #25
0
 public IUploadRequest StartUploadFile(IBinaryContent fileContent, int chunkSize = DEFAULT_UPLOAD_CHUNK_SIZE, long? replaceVideoId = null)
 {
     try
     {
         return StartUploadFileAsync(fileContent, chunkSize, replaceVideoId).RunSynchronouslyWithCurrentCulture();
     }
     catch (AggregateException ex)
     {
         ExceptionDispatchInfo.Capture(ex.InnerException).Throw();
         return null;
     }
 }
コード例 #26
0
 public override void Read(Util.DataDeserializer reader)
 {
     base.Read(reader);
     Key = Deserialize(reader) as IBinaryContent;
 }
コード例 #27
0
        /// <summary>
        /// upload picture asynchronously
        /// </summary>
        /// <param name="fileContent">fileContent</param>
        /// <param name="clipId">Clip Id</param>
        /// <returns>upload pic </returns>
        private async Task <string> UploadPictureAsync(IBinaryContent fileContent, long clipId)
        {
            try
            {
                if (!fileContent.Data.CanRead)
                {
                    throw new ArgumentException("fileContent should be readable");
                }

                if (fileContent.Data.CanSeek && fileContent.Data.Position > 0)
                {
                    fileContent.Data.Position = 0;
                }

                // Get the URI of the thumbnail
                var request = _apiRequestFactory.GetApiRequest(AccessToken);
                request.Method = HttpMethod.Get;
                request.Path   = Endpoints.Video;
                request.UrlSegments.Add("clipId", clipId.ToString());


                var response = await request.ExecuteRequestAsync <Video>().ConfigureAwait(false);

                CheckStatusCodeError(null, response, "Error getting video settings.");

                // Get the upload link for the thumbnail
                var postRequest = _apiRequestFactory.AuthorizedRequest(
                    AccessToken,
                    HttpMethod.Post,
                    response.Content.Metadata.Connections.Pictures.Uri,
                    null
                    );

                var postResponse = await postRequest.ExecuteRequestAsync().ConfigureAwait(false);

                CheckStatusCodeError(null, postResponse, "Error posting thumbnail placeholder.");
                JObject.Parse(postResponse.Text).TryGetValue("link", out var link);
                JObject.Parse(postResponse.Text).TryGetValue("uri", out var uri);

                // Upload the thumbnail image file
                var putRequest = new NonApiRequest
                {
                    Path   = link.ToString(),
                    Method = HttpMethod.Put,
                    Body   = new ByteArrayContent(await fileContent.ReadAllAsync().ConfigureAwait(false))
                };
                var putResponse = await putRequest.ExecuteRequestAsync().ConfigureAwait(false);

                CheckStatusCodeError(null, putResponse, "Error putting thumbnail data.");

                return(uri.ToString());
            }
            catch (Exception ex)
            {
                if (ex is VimeoApiException)
                {
                    throw;
                }

                throw new VimeoUploadException("Error Uploading picture.", null, ex);
            }
        }