jquery fileupload is not working on Mobile devices

I am using jquery file upload with progress bar in my (php & Jquery based) application to upload videos , it’s working fine on desktop .

but on mobile devices when mobile phone goes in sleep mode for 3-4 minutes it stop uploading .
It show this on progress “Non uploading in progress Non MB of Non MB”

Read More

Why this happening any idea

     jQuery(file_upload_selector).fileupload({
        dropZone: $(this),
        url: url,
        dataType: 'text',
        async: true,
        beforeSend: function(xhr) {
            jQuery('.err').hide();
            add_more.sort();
            var file = this.files[0],
                fl_type = file.type;

            var mim_t = fl_type.split("/")[0];

            //disable on max file count 

            if (section_type == 'video') {


                for (var k = 0; k < 2; k++) {
                    var src = jQuery('#vd_image' + k).attr('src');
                    if (src == 'http://www.example.com/wp-content/themes/example/assets/images/video-placeholder.jpg') {
                        var onev = 1;
                    }
                }
                for (var k = 1; k < 6; k++) {
                    var src = jQuery('#vd_image' + k).attr('src');
                    if (src == 'http://www.example.com/wp-content/themes/example/assets/images/placeholder.jpg') {
                        var twov = 1;
                    }

                }

            } else {
                for (var k = 0; k < 4; k++) {
                    var src2 = jQuery('#ch_image' + k).attr('src');
                    if (src2 == 'http://www.example.com/wp-content/themes/example/assets/images/placeholder.jpg') {
                        var hidevcon3 = 1;
                    }
                }
            }


            if (onev == '1' && fl_type != 'video/mp4' && twov != '1') {
                alert('Please upload video only');
                return false;
            }



            // disable ends 

            if (section_type == 'video' && add_more[0] == "0" && mim_t == "video") {
                jQuery('#_filechk').val(1);

                jQuery(uploading_div_id + "-0").css("display", "block");
            } else if (section_type == 'video' && add_more[0] == "0" && mim_t == "image") {
                jQuery('#_filechk').val(0);
                jQuery(uploading_div_id + "-" + add_more[0 + 1]).css("display", "block");
            } else if (section_type == 'video' && add_more[0] != "0" && mim_t == "image") {
                jQuery('#_filechk').val(0);
                jQuery(uploading_div_id + "-" + add_more[0]).css("display", "block");
            } else {
                jQuery('#_filechk').val(0);

                jQuery(uploading_div_id + "-" + add_more[0]).css("display", "block");
            }

        },
        progressall: function(e, data) {


            chckp = jQuery('#_filechk').val();

            if (section_type == 'video') {
                document.getElementById("ch_ima").disabled = true;
                jQuery('#progressing').show();
                jQuery('.cn-v').show();
                var progress = parseInt(data.loaded / data.total * 100, 10);


                $('.progress-bar-all').css(
                    'width',
                    progress + '%'
                );

                $('#vid-info').html(progress + '%' + ' uploading in progress ' + formatBytes(data.loaded) + ' of ' + formatBytes(data.total));
                if (progress == '100') {
                    $('#vid-info').html('');
                    document.getElementById("ch_ima").disabled = false;
                    jQuery('.uploadings').hide();
                    jQuery('.convert').show();
                    setTimeout(function() {
                        jQuery('#progressing').hide();
                        jQuery('.cn-v').hide();
                    }, 3000);
                }


            } else {
                jQuery('#progressing-i').show();
                jQuery('.cn-i').show();
                document.getElementById("ch_img").disabled = true;
                var progress = parseInt(data.loaded / data.total * 100, 10);
                $('.progress-bar-all-i').css(
                    'width',
                    progress + '%'
                );
                $('.progress-bar-all').html(progress + '%');
                $('#ing-info').html('uploading in progress ' + formatBytes(data.loaded) + ' of ' + formatBytes(data.total));
                if (progress == '100') {
                    document.getElementById("ch_img").disabled = false;
                    setTimeout(function() {
                        jQuery('#progressing-i').hide();
                        jQuery('.cn-i').hide();
                    }, 3000);
                    $('#ing-info').html('');
                }

            }


        },
        add: function(e, data) {

            var uploadErrors = [];
            // alert(data.originalFiles[0]['size']);
            var $image_format = 'jpg|jpeg|jpe|png|gif';
            if (section_type == 'video') {
                var $audio_format = 'mp4|flv';
            }
            var $all_formats = $image_format + '|' + $audio_format;
            var acceptFileTypes = "(.|/)(" + $all_formats + ")$";
            acceptFileTypes = new RegExp(acceptFileTypes, "i");
            var filetipe = data.originalFiles[0]['type'];

            var res = filetipe.split("/");
            if (jQuery('#videourl_link').length) {
                if (res[0] == 'video') {
                    uploadErrors.push('Please remove privious video first');
                }
            }
            if (data.originalFiles[0]['type'].length && !acceptFileTypes.test(data.originalFiles[0]['type'])) {
                uploadErrors.push('Not an accepted file type');
            }
            if (data.originalFiles[0]['size'] > 209715200) {
                uploadErrors.push('Max allowed size is 200MB ');
            }
            if (uploadErrors.length > 0) {
                alert(uploadErrors.join("n"));
            } else {
                jqXHR = data.submit();
            }
            jQuery('.cncil').click(function(e) {

                jqXHR.abort();
                jQuery('#ch_ima').prop("disabled", false);
                jQuery('#ch_img').prop("disabled", false);
                jQuery('#vid-info').html('');
                jQuery('#ing-info').html('');
                jQuery('.uploading').hide();
                jQuery('.progress').hide();
                jQuery('.cncil').hide();
            });
        },
        done: function(e, data) {
            var obj = jQuery.parseJSON(data.result);
            var r = obj.url;
            var file_location = obj.file;
            var f_mime_type = obj.f_mime_type;
            add_more.sort();
            if (f_mime_type == 'video') {
                var vid_loc = obj.video_file;
            }

            // console.log(data.result);
            if (check_if_image_exist(add_more[0]) != true) {
                if (f_mime_type == 'video' && section_type == 'video') {
                    var extention = vid_loc.split('.').pop();
                    if (extention == 'mp4' || extention == 'flv') {
                        jQuery(image_selector + "0").attr("src", r);
                        jQuery(close_span_id + "0").css("display", "block");
                        jQuery(uploading_div_id + "-0").css("display", "none");
                        removeItem = 0;
                        if (jQuery('#videourl_link').length) {} else {
                            $(file_upload_section).append('<input type="hidden" id="remove_video"  value="' + vid_loc + '">');
                            $(file_upload_section).append('<input type="hidden" class="' + section_type + '_validator" id="' + section_type + '_image_link-' + removeItem + '" name="' + section_type + '_image_link[]" value="' + r + '">');
                            $(file_upload_section).append('<input type="hidden" class="remove-item" id="' + section_type + '_image_path-' + removeItem + '" value="' + file_location + '">');
                            $(file_upload_section).append('<input type="hidden" class="' + section_type + '_validator" id="videourl_link" name="videourl_link" value="' + r + '">');
                        }
                    } else {
                        jQuery(uploading_div_id + "-0").css("display", "none");
                        jQuery("#video_file").show();
                        add_more.push("0");
                    }
                } else if (f_mime_type == 'image' && section_type == 'video' && add_more[0] == 0) {

                    var extention = r.split('.').pop();
                    if (extention == 'jpg' || extention == 'png' || extention == 'jpeg' || extention == 'gif') {

                        jQuery(image_selector + "" + add_more[0 + 1]).attr("src", r);
                        jQuery(close_span_id + "" + add_more[0 + 1]).css("display", "block");
                        jQuery(uploading_div_id + "-" + add_more[0 + 1]).css("display", "none");
                        removeItem = add_more[0 + 1];
                        $(file_upload_section).append('<input type="hidden" class="' + section_type + '_validator" id="' + section_type + '_image_link-' + removeItem + '" name="' + section_type + '_image_link[]" value="' + r + '">');
                        $(file_upload_section).append('<input type="hidden" class="remove-item" id="' + section_type + '_image_path-' + removeItem + '" value="' + file_location + '">');

                    } else {
                        jQuery(uploading_div_id + "-" + add_more[0 + 1]).css("display", "none");
                        jQuery("#imagev_vfile").show();
                    }
                } else {

                    if (r == null) {
                        if (section_type == 'video') {
                            jQuery(uploading_div_id + "-" + add_more[0]).css("display", "none");
                            jQuery('#support_file').show();
                        } else {
                            jQuery(uploading_div_id + "-" + add_more[0]).css("display", "none");
                            jQuery('#images_file').show();
                        }
                    } else {
                        var extention = f_mime_type.split('.').pop();
                        if (extention == 'image') {
                            jQuery(image_selector + "" + add_more[0]).attr("src", r);
                            jQuery(close_span_id + "" + add_more[0]).css("display", "block");
                            jQuery(uploading_div_id + "-" + add_more[0]).css("display", "none");
                            removeItem = add_more[0];
                            $(file_upload_section).append('<input type="hidden" class="' + section_type + '_validator" id="' + section_type + '_image_link-' + removeItem + '" name="' + section_type + '_image_link[]" value="' + r + '">');
                            $(file_upload_section).append('<input type="hidden" class="remove-item" id="' + section_type + '_image_path-' + removeItem + '" value="' + file_location + '">');

                        } else {
                            jQuery(uploading_div_id + "-" + add_more[0]).css("display", "none");
                            jQuery("#images_file").show();
                        }
                    }
                }
            }
            var extention = f_mime_type.split('.').pop();
            if (section_type == 'channel' && extention != 'image') {} else {
                add_more = jQuery.grep(add_more, function(value) {
                    return value != removeItem;
                });
            }
            if (section_type == 'video') {


                for (var k = 0; k < 2; k++) {
                    var src = jQuery('#vd_image' + k).attr('src');
                    if (src == 'http://www.example.com/wp-content/themes/example/assets/images/video-placeholder.jpg') {
                        var onev = 1;
                    }
                }
                for (var k = 1; k < 6; k++) {
                    var src = jQuery('#vd_image' + k).attr('src');
                    if (src == 'http://www.example.com/wp-content/themes/example/assets/images/placeholder.jpg') {
                        var twov = 1;
                    }

                }
                if (onev != '1' && twov != '1') {
                    document.getElementById("ch_ima").disabled = true;
                }
            } else {
                for (var k = 0; k < 5; k++) {
                    var src2 = jQuery('#ch_image' + k).attr('src');
                    if (src2 == 'http://www.example.com/wp-content/themes/example/assets/images/placeholder.jpg') {
                        var hidevcon3 = 1;
                    }
                }
                if (hidevcon3 != '1') {
                    document.getElementById("ch_img").disabled = true;
                }
            }



            jQuery('.uploadings').show();
            jQuery('.convert').hide();
            add_more.sort();
        },
    }).prop('disabled', !jQuery.support.fileInput)
    .parent().addClass(jQuery.support.fileInput ? undefined : 'disabled');

function check_if_image_exist(check_val) {
    for (var x = 0; x < add_more.length; x++) {
        if (add_more[x] === check_val) {

            return false;
        }
    }
}

jQuery(".remove-" + section_type + "-image").click(function() {
    if (section_type == 'channel') {
        document.getElementById("ch_img").disabled = false;
    } else if (section_type == 'video') {
        document.getElementById("ch_ima").disabled = false;
    }
    var spanID = jQuery(this).attr("id");
    var arr = spanID.split('-')[1];
    file_location = jQuery("#" + section_type + "_image_path-" + arr).val();
    //alert(file_location);

    jQuery.ajax({
        type: "POST",
        url: wpAjax.ajaxurl,
        data: {
            action: 'remove_images',
            image_loc: file_location
        },
        beforeSend: function() {
            // Handle the beforeSend event
            if (image_selector == '#ch_image') {
                jQuery("#i-removing-" + arr).css("display", "block");
            }
            if (image_selector == '#vd_image') {
                jQuery("#v-removing-" + arr).css("display", "block");
            }
        },
        success: function(resp) {
            if (resp == "200") {
                var fl = delete_video_file();
                if (image_selector == '#ch_image') {
                    jQuery("#i-removing-" + arr).css("display", "none");
                }
                if (image_selector == '#vd_image') {
                    jQuery("#v-removing-" + arr).css("display", "none");
                }
                var ext = file_location.split('.').pop();

                if (image_selector == '#vd_image' && arr == '0') {
                    jQuery(image_selector + "" + arr).attr("src", templateUrl + "/assets/images/video-placeholder.jpg");
                    jQuery(close_span_id + "" + arr).css("display", "none");
                    jQuery("#" + section_type + "_image_path-" + arr).remove();
                    jQuery("#" + section_type + "_image_link-" + arr).remove();
                    if (section_type == 'video' && arr == '0') {
                        jQuery('#remove_video').remove();
                        jQuery('#videourl_link').remove();

                    }

                } else {
                    jQuery(image_selector + "" + arr).attr("src", templateUrl + "/assets/images/placeholder.jpg");
                    jQuery(close_span_id + "" + arr).css("display", "none");
                    jQuery("#" + section_type + "_image_path-" + arr).remove();
                    jQuery("#" + section_type + "_image_link-" + arr).remove();
                }
                add_more.push(arr);
            }
            return;
        }
    });
});
jQuery(".remove-echannel-image").click(function() {
    var spanID = jQuery(this).attr("id");
    var arr = spanID.split('-')[1];
    file_location = jQuery("#" + section_type + "_image_path-" + arr).val();
    //alert(file_location);

    jQuery(close_span_id + "" + arr).css("display", "none");
    jQuery("#i-removing-" + arr).css("display", "none");
    jQuery("#channel_image_path-" + arr).remove();
    jQuery("#channel_image_link-" + arr).remove();
    jQuery("#ch_image" + arr).attr("src", templateUrl + "/assets/images/placeholder.jpg");
    return;
}); 

Related posts

Leave a Reply