Search code examples
fine-uploader

How do I show only 1 scaled image in fineuploader


I want to upload 2 scaled images and I do not want to upload the original image. To do this, I set sendOriginal to false. If I set hideScaled to true, no files show in the uploader. If set set hideScaled to false, both scaled images show up in the list. I realize that the documentation says not to use both options this way. Is there another way to achieve what I want? How do I make fineuploader show only 1 file on the file list no matter how many scaled images it has?


Solution

  • I ran into this exact same problem. I also wanted to rename the larger scale to match the original filename and to pass a custom parameter so the server script could sort the images into the db based on scale size.

    I used this method as a hackish substitute for an onScaled event. If anyone is still interested.

    // Must be onSubmitted, not onSubmit or the DOM element won't be rendered yet.
    onSubmitted : function(id, name) {
    
        // scaling.sizes.name = 'thumb'
        if (name.toLowerCase().lastIndexOf(' (thumb).jpg') !== -1) {
    
            // Hide the element displaying the thumbnail.
            qq(this.getItemByFileId(id)).hide();
    
            // Good place to include any custom parameters based on scale size.
            this.setParams({gpsize : 'thumb'}, id);
        }
    
        // scaling.sizes.name = 'large'
        else if (name.toLowerCase().lastIndexOf(' (large).jpg') !== -1) {
    
            this.setParams({gpsize : 'large'}, id);
    
            // If needed rename file in this event, not before, since filename
            // is the hackish hook needed to connect scale size to file id.
            var newName = name.slice(0, name.toLowerCase().lastIndexOf(' (large).jpg')) + '.jpg';
            this.setName(id, newName);
        }
        return true;
    }
    

    It's not perfect, but it gets the job done without bushwhacking through the script files.