public (UploadResult Result, Response Response) Upload(Core.Services.UploadRequest request) { try { var client = new VimeoClient(config.VideoSettings.Token); var ticket = client.GetUploadTicketAsync().Result; IBinaryContent file = new BinaryContent(request.Stream, request.ContentType); var uploadRequest = client.UploadEntireFileAsync(file).Result; var verificationResult = client.VerifyUploadFileAsync(uploadRequest).Result; Task.WaitAll(client.UpdateVideoMetadataAsync(uploadRequest.ClipId.Value, new VideoUpdateMetadata { Description = request.Description, Name = request.Title, Privacy = VideoPrivacyEnum.Password, AllowDownloadVideo = false, Password = config.VideoSettings.Password }) ); var albumResult = client.AddToAlbumAsync(4877366, uploadRequest.ClipId.Value).Result; Task.WaitAll(client.CompleteFileUploadAsync(uploadRequest)); var video = client.GetVideoAsync(uploadRequest.ClipId.Value).Result; string thumbnailUrl = null; if (video?.pictures?.sizes != null && video.pictures.sizes.Count > 0) { thumbnailUrl = video.pictures.sizes[0].link; } return(new UploadResult(uploadRequest.ClipId.ToString(), video.StandardVideoLink, thumbnailUrl), Response.CreateSuccessResponse()); }catch (Exception ex) { return(null, Response.CreateResponse(ex)); } }
public async Task <IActionResult> Upload() //HttpPostedFile(.net) == IFormFile { var files = Request.Form.Files; //Request.File(.net) == Request.Form.Files IFormFile file = files[0]; //HttpPostedFileBase(.net) == IFormFile string uploadstatus = ""; try { if (file != null) { VimeoClient vimeoClient = new VimeoClient(accessToken); var authcheck = await vimeoClient.GetAccountInformationAsync(); if (authcheck.Name != null) { IUploadRequest uploadRequest = new UploadRequest(); BinaryContent binaryContent = new BinaryContent(file.OpenReadStream(), file.ContentType); //InputStream(.net) == OpenReadStream() long chunksizeLong = 0; //tamanho do pedaço long contentleght = file.Length; //tamanho do arquivo em bytes long temp1 = contentleght / 1024; //tamanho do arquivo em Kilobytes if (temp1 > 1) { chunksizeLong = temp1 / 1024; //tamanho do arquivo em Megabytes chunksizeLong = chunksizeLong / 10; chunksizeLong = chunksizeLong * 1048576; //1048576 bytes(1024 * 1024) = 1 MB } else { chunksizeLong = 1048576; //chunk size equal to 1 MB } int chunksize = unchecked ((int)chunksizeLong); //converte de long para int (https://stackoverflow.com/questions/858904/can-i-convert-long-to-int) uploadRequest = await vimeoClient.UploadEntireFileAsync(binaryContent, chunksize, null); uploadstatus = String.Concat("file uploaded ", "https://vimeo.com/", uploadRequest.ClipId.Value.ToString(), "/none"); //_applicationDbContext.ApplicationUser = uploadRequest.ClipId.Value; var user = await _userManager.GetUserAsync(User); //obtém Denizard //user.ClipIdUser = uploadRequest.ClipId.Value; // coloco o ClipId no user Denizard user.UploadRequests.Add(new LocalUploadRequest( uploadRequest.ChunkSize, uploadRequest.BytesWritten, uploadRequest.IsVerifiedComplete, uploadRequest.ClipUri, uploadRequest.FileLength, uploadRequest.ClipId, user )); _applicationDbContext.SaveChanges(); // salvo as mudanças do user Denizard } } } catch (Exception e) { uploadstatus = "not uploaded: " + e.Message; if (e.InnerException != null) { uploadstatus += e.InnerException.Message; } } ViewBag.UploadStatus = uploadstatus; return(View()); }