Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Continue Upload When Internet Connected

$
0
0

hi,
with this code i upload my file in .net core ,
i want when internet is disconnected , the upload operation is paused and
when internet is connected it continue the upload
how can i do this in javascript & .net core?

 document.getElementById('upload-video').addEventListener('change', function (event) {

       var file = event.target.files[0];
       console.log($("#upload-video").val());
       var fileReader = new FileReader();
       var extension = file.type.split("/");

           fileReader.onload = function () {
               var blob = new Blob([fileReader.result], { type: file.type });
               var url = URL.createObjectURL(blob);
               var video = document.createElement('video');
               var timeupdate = function () {
                   if (snapImage()) {
                       video.removeEventListener('timeupdate', timeupdate);
                       video.pause();
                   }
               };
               video.addEventListener('loadeddata', function () {
                   GetDuration(video.duration);


               });

               var snapImage = function () {
                   var canvas = document.createElement('canvas');

                   canvas.width = video.videoWidth;
                   canvas.height = video.videoHeight;

                   canvas.getContext('2d').drawImage(video, 0, 0, canvas.width, canvas.height);
                   var image = canvas.toDataURL();
                   var success = image.length > 10000;
                   var image = canvas.toDataURL();
                   if (success) {
                       var img = document.getElementById('video-image');
                       img.src = image;

                       if (document.contains(document.getElementById("upload-preview-loader"))) {
                           document.getElementById('upload-preview-loader').remove();
                       }

                       img.hidden = false;
                       document.getElementById('div-image').appendChild(img);
                       URL.revokeObjectURL(url);

                   }

                   return success;
               };
               video.addEventListener('timeupdate', timeupdate);
               video.preload = 'metadata';
               video.src = url;
               video.muted = true;
               video.playsInline = true;
               video.currentTime = 30;
               video.play();


           
               SendVideo();



           fileReader.readAsArrayBuffer(file);
       }
   });
function SendVideo() {

    var image = $("#upload-video").get(0).files;
    var aVF = new FormData();
    aVF.append("file", image[0])$.ajax({
        method: 'POST',
        url: '/Video/Upload',
        data: aVF,
        processData: false,
        contentType: false,
        xhr: function () {$("#progress-bar-video").addClass("bg-info");$("#progress-bar-video").removeClass("bg-success");
            var xhr = new window.XMLHttpRequest();
            xhr.upload.addEventListener("progress", function (evt) {
                if (evt.lengthComputable) {
                    //console.log(evt.loaded + " / " + evt.total);
                    var progress = Math.round((evt.loaded / evt.total) * 100);$(".progress-bar").css("width", progress + "%").attr("aria-valuenow", progress);$(".progress-bar").html('(' + progress + "%) در حال بارگذاری");
                }
            }, false);
            return xhr;
        },
        success: function (data) {

         //do something
            }

            //




        },
        complete: function (data) {
            //do something
        },
        error: function (result) {
        }
    });
}





Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>