Esempio n. 1
0
 private void UploadButtonClick(object sender, RoutedEventArgs e)
 {
     if (Path.GetExtension(FileToUpload.Path).ToLower() == ".mp4")
     {
         var uploader = new VideoUploader();
         Helper.ShowNotify("We will notify you once your video uploaded...", 3000);
         uploader.UploadVideo(FileToUpload, ThumbnailFile, CaptionText.Text, VideoBitmapDecoder, CurrentCroppedRectForVideo);
     }
     else
     {
         var uploader = new PhotoUploaderHelper();
         Helper.ShowNotify("We will notify you once your photo uploaded...", 3000);
         uploader.UploadSinglePhoto(FileToUpload, CaptionText.Text, UserTags);
         MainPage.Current?.ShowMediaUploadingUc();
         if (NavigationService.Frame.CanGoBack)
         {
             NavigationService.GoBack();
         }
     }
     //using (var photo = new PhotoHelper())
     //{
     //    var fileToUpload = await photo.SaveToImageForPost(files[0]);
     //    Random rnd = new Random();
     //    Uploader.UploadSinglePhoto(fileToUpload, "TEEEEEEEEEEST\r\n\r\n\r\n" + DateTime.Now.ToString());
     //}
 }
Esempio n. 2
0
 public ActionResult AddNews([Bind(Prefix = "Item1")] News item, HttpPostedFileBase resim, HttpPostedFileBase video)
 {
     item.CreatedBy = (Session["admin"] as AppUser).UserName;
     item.ImagePath = ImageUploader.UploadImage("~/Pictures", resim);
     item.VideoPath = VideoUploader.UploadVideo("~/Videos", video);
     news_repo.Add(item);
     return(RedirectToAction("ListNews"));
 }
Esempio n. 3
0
        public async Task UploadAsAdVideoAsync()
        {
            var response = await VideoUploader.UploadAsAdVideoAsync(TestsBase.TestVideoPath, TestsBase.AdAccountId, TestsBase.AccessToken, _request);

            Assert.IsTrue(response.Code == ResponseCode.SUCCESS, response.ReasonPhrase ?? String.Empty);

            var jobj = JObject.Parse(response.Data);

            Assert.IsTrue(jobj["id"] != null && !String.IsNullOrEmpty(jobj["id"].ToString()));
        }
Esempio n. 4
0
        public async Task UploadInChunksAsync()
        {
            var response = await VideoUploader.UploadInChunksAsync(TestsBase.TestVideoPath, TestsBase.PageId, TestsBase.PageAccessToken, _request);

            Assert.IsTrue(response.Code == ResponseCode.SUCCESS, response.ReasonPhrase ?? String.Empty);

            var jobj = JObject.Parse(response.Data);

            Assert.IsTrue((jobj["success"] != null && Boolean.Parse(jobj["success"].ToString()) == true) &&
                          (jobj["video_id"] != null && !String.IsNullOrEmpty(jobj["video_id"].ToString())));
        }
Esempio n. 5
0
 public ActionResult UpdateNews([Bind(Prefix = "Item1")] News item, HttpPostedFileBase resim, HttpPostedFileBase video)
 {
     if (resim != null)
     {
         item.ImagePath = ImageUploader.UploadImage("~/Pictures", resim);
     }
     if (video != null)
     {
         item.VideoPath = VideoUploader.UploadVideo("~/Videos", video);
     }
     item.ModifiedBy = (Session["admin"] as AppUser).UserName;
     news_repo.Update(item);
     return(RedirectToAction("ListNews"));
 }
Esempio n. 6
0
 private void UploadButtonClick(object sender, RoutedEventArgs e)
 {
     if (Path.GetExtension(FileToUpload.Path).ToLower() == ".mp4")
     {
         var uploader = new VideoUploader();
         Helper.ShowNotify("We will notify you once your video uploaded...", 3000);
         uploader.UploadVideo(FileToUpload, ThumbnailFile, CaptionText.Text, Editor.ScaledCropRect);
     }
     else
     {
         var uploader = new PhotoUploaderHelper();
         Helper.ShowNotify("We will notify you once your photo uploaded...", 3000);
         uploader.UploadSinglePhoto(FileToUpload, CaptionText.Text, UserTags);
         MainPage.Current?.ShowMediaUploadingUc();
         if (NavigationService.Frame.CanGoBack)
         {
             NavigationService.GoBack();
         }
     }
 }
Esempio n. 7
0
 public MoviesController(MovieContext context, VideoUploader videoUploader)
 {
     _context       = context;
     _videoUploader = videoUploader;
 }
Esempio n. 8
0
        /// <summary>
        ///     Publishes video ad to facebook with a specified cover as an asynchronous operation.
        /// </summary>
        /// <param name="video">
        ///     The filepath of the ad video.
        /// </param>
        /// <param name="cover">
        ///     The url or filepath of the video cover. Sets to null or an empty string to use the thumbnail that
        ///     generated by facebook as the cover.
        /// </param>
        /// <param name="request">
        ///     An object of <see cref="AdCreativeCreatingRequest"/>, which contains most of publish infomation.
        /// </param>
        /// <param name="adAccountId">
        ///     The ad account id of user.
        /// </param>
        /// <param name="accessToken">
        ///     User access token.
        /// </param>
        /// <param name="pageAccessToken">
        ///     Page access token.
        /// </param>
        /// <param name="publish">
        ///     If true, the photo ad will be published to a facebook page immediately.
        /// </param>
        /// <param name="threshold">
        ///     If the filesize (in MByte) of video exceeded this value, the video will be uploaded in resumable upload;
        ///     otherwise, non-resumable upload. The default threshold is set to 50MB.
        /// </param>
        /// <returns>
        ///     The task object representing the asynchronous operation.
        /// </returns>
        /// <exception cref="FileNotFoundException">
        ///     Throw if the target video or cover file doesn't exist.
        /// </exception>
        public static async Task <ResponseMessage <string> > PublishVideoAdAsync(string video, string cover, AdCreativeCreatingRequest request, string adAccountId, string accessToken, string pageAccessToken, bool publish, int threshold = 50)
        {
            ResponseMessage <string> response = null;

            JObject jobj = null;

            var videoId    = String.Empty;
            var coverUrl   = String.Empty;
            var adCreative = new AdCreative();

            // 1. Gets the video_id.
            #region Uploads video to facebook.
            if (!File.Exists(video))
            {
                throw new FileNotFoundException($"Cannot find file {video}");
            }

            var videoInfo            = new FileInfo(video);
            var videoSize            = videoInfo.Length;
            var enableChunkedUpload  = videoSize > (50L * 1024 * 1024);
            var videoCreatingRequest = new VideoCreatingRequest(videoInfo.Extension)
            {
                Name  = videoInfo.Name,
                Title = Path.GetFileNameWithoutExtension(video)
            };

            response = enableChunkedUpload ?
                       await VideoUploader.UploadAsAdVideoInChunksAsync(video, adAccountId, accessToken, videoCreatingRequest) :
                       await VideoUploader.UploadAsAdVideoAsync(video, adAccountId, accessToken, videoCreatingRequest);

            if (response.Code == ResponseCode.SUCCESS)
            {
                jobj = JObject.Parse(response.Data);

                if (enableChunkedUpload)
                {
                    // Parses resumable upload result.
                    if (jobj["video_id"] != null && !String.IsNullOrEmpty(jobj["video_id"].ToString()))
                    {
                        videoId = jobj["video_id"].ToString();
                    }
                }
                else
                {
                    // Parses non-resumable upload result.
                    if (jobj["id"] != null && !String.IsNullOrEmpty(jobj["id"].ToString()))
                    {
                        videoId = jobj["id"].ToString();
                    }
                }

                if (String.IsNullOrEmpty(videoId))
                {
                    return(new ResponseMessage <string>
                    {
                        Code = ResponseCode.UNKNOWN_ERROR,
                        ReasonPhrase = $"Failed to upload video {video} to facebook."
                    });
                }
            }
            else
            {
                return(response);
            }
            #endregion

#if DEBUG
            System.Diagnostics.Debug.WriteLine($"Got video_id: {videoId}");
#endif

            // 2. Gets the url of cover.
            if (!String.IsNullOrEmpty(cover))
            {
                // Customizes cover.
#pragma warning disable SA1008
                var(AdPhotoUrl, AdPhotoResponse) = await GetAdPhotoUrlAsync(cover, adAccountId, accessToken);

#pragma warning restore SA1008

                if (String.IsNullOrEmpty(AdPhotoUrl))
                {
                    return(AdPhotoResponse);
                }

                coverUrl = AdPhotoUrl;
            }

            /* The thumbnail won't be generated until the video has been decoded by facebook successfully,
             * just wait for a while.
             * */
            await Task.Delay(10_000);

#pragma warning disable SA1008
            var(ThumbnailUrl, ThumbnailResponse) = await GetVideoThumbnailAsync(videoId, accessToken, 20);

#pragma warning restore SA1008

            if (String.IsNullOrEmpty(cover))
            {
                if (String.IsNullOrEmpty(ThumbnailUrl))
                {
                    return(ThumbnailResponse);
                }

                coverUrl = ThumbnailUrl;
            }

#if DEBUG
            System.Diagnostics.Debug.WriteLine($"Got cover_url: {coverUrl}");
#endif

            // 3. Posts ad creative creating request.
            request.ObjectStorySpec.VideoData.VideoId = videoId;
            request.ObjectStorySpec.VideoData.Cover   = coverUrl;

#pragma warning disable SA1008
            var(AdCreativeId, AdCreativeResponse) = await PostAdCreativeAsync(request, adAccountId, accessToken);

#pragma warning restore SA1008

            if (String.IsNullOrEmpty(AdCreativeId))
            {
                return(AdCreativeResponse);
            }

            adCreative.Id = AdCreativeId;

#if DEBUG
            System.Diagnostics.Debug.WriteLine($"Got ad_creative_id: {AdCreativeId}");
#endif

            if (publish)
            {
                // 4. Publishes ad creative.
                response = await adCreative.PublishAsync(accessToken, pageAccessToken);
            }

            return(response);
        }
 public CitrinaUploader()
 {
     Photos = new PhotosUploader();
     Video  = new VideoUploader();
     Docs   = new DocsUploader();
 }