LPology / Simple-Ajax-Uploader

Javascript file upload plugin with progress bar support. Works in all major browsers, including IE7+, Chrome, Firefox, Safari, and Opera. No dependencies - use it with or without jQuery.
995 stars 267 forks source link

how to one by one upload file with {multiple: true} option? #148

Closed suhaotian closed 8 years ago

suhaotian commented 8 years ago

pls help me :cry:

enumag commented 8 years ago

{maxUploads:1} ?

suhaotian commented 8 years ago

@enumag It didn't work: ti50 t4 4 sfj4w d3tb_nc

last two don't upload ...

LPology commented 8 years ago

Can you post your code

suhaotian commented 8 years ago

yes,

      var cert_uploader_ss = new ss.SimpleUpload({
            button: query('cert_upload_btn'),
            url: '/v.php/Home/Index/getApi.html',
            debug: true,
            multipart: true,
            multiple: true,
            maxUploads: 1,
            // queue: false,
            name: 'cert',
            allowedExtensions: ['jpg', 'jpeg', 'png', 'gif'],
            accept: 'image/*',
            autoSubmit: false,
            responseType: 'html',
            onChange: function(filename, extension, uploadBtn, fileSize, file) {
                console.log(filename)
                var isEqual = cert_dom_wrap.querySelector('#_' + (filename + fileSize).replace('.', '_'))
                if(!!isEqual) {
                    alert('您已上传该图片!')
                    cert_uploader_ss.clearQueue()
                    return false
                }
                maxI++
                if (maxI == 5) {
                    cert_btn.style.display = 'none'
                }
                // cert_btn.style.display = 'none'
                if(maxI > 5) {
                    return false
                }

                var self = this;

                wrap_img = document.createElement('div')
                wrap_img.setAttribute('id', ('_' + filename + fileSize).replace('.', '_'))
                cert_img = document.createElement('img')
                wrap_img.classList.add('uploader_file')
                cert_overlay = document.createElement('div')
                cert_overlay.className = 'uploader_file_overlay'
                cert_overlay.style.display = 'block'
                cert_overlay.textContent = '正在上传...'

                wrap_img.appendChild(cert_img)
                wrap_img.appendChild(cert_overlay)
                cert_dom_wrap.appendChild(wrap_img)

            },
            onProgress: function(n){
                // console.log(n) // 进度条

            },
            onSubmit: function( filename, extension, uploadBtn, fileSize) {   
                var self = this;
                self.setData({
                    name: 'cert',
                    hash: 'custom_hash',
                    reType: 'html'
                })

            },     
LPology commented 8 years ago

How are you submitting each upload since you have autoSubmit: false

suhaotian commented 8 years ago

@LPology :astonished: thank you !!

LPology commented 8 years ago

One other tip: if you only want to remove one file inside of onChange() here:

                if(!!isEqual) {
                    alert('您已上传该图片!')
                    cert_uploader_ss.clearQueue()
                    return false
                }

You may want to use removeCurrent() instead of clearQueue(). Using clearQueue() clears out all selected fies, whereas removeCurrent() only removes the current file.

suhaotian commented 8 years ago

@LPology :smile: thank you !!