1

I have created a vf page to upload MultipleFiles at a time. Now using AJAX request i am passing the file to Salesforce server and using addEventListener to show the progress bar, The issue here is the progress bar runs very fast within no time of span for small files and if i try to upload single file the progress bar it not even shown.

What may be the issue here.

Posting required part of AJAX call.

$.ajax({  
                            url: '/services/data/v45.0/sobjects/ContentVersion',  
                            data: JSON.stringify(conVer_object ),  
                            type: 'POST',  
                            processData: false,  
                            contentType: false,  
                            headers: {'Authorization': 'Bearer {!$Api.Session_ID}', 'Content-Type': 'application/json'},  
                            xhr: function(){  
                                var xhr = new window.XMLHttpRequest();  
                                //Upload progress  
                                xhr.upload.addEventListener("progress", function(evt){  
                                    if (evt.lengthComputable) {  
                                        $('#progress_bar_container').css('display', 'block');  
                                        var percentComplete = evt.loaded / evt.total;  
                                        console.log('percentComplete '+percentComplete );  
                                        var percentCompletex= percentComplete*100;  
                                        $('#percentText').html("Uploading. Please wait... "+Math.round(percentCompletex)+"%");  
                                        $('.progress').css('width', percentCompletex+ "%");  
                                        if(percentCompletex == 100){  
                                            $('#progress_bar_container').css('display', 'none');  
                                        }  
                                    }  
                                }, false);  
                                return xhr;  
                            },  

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.