Search code examples
angularfilepicker.io

Filepicker.io (Filestack) uploads twice


I'm using Filestack (aka filepicker.io) in my Angular 4 app. When I select a file (and before uploading that), it become uploaded automaticlly. So after I press Upload, I'll have 2 files uploaded. What am I doing wrong? :(

this is my code:

async showPicker() {

    const client = filestack.init('MyApiKey');

    const result = await client.pick({
        fromSources: ['local_file_system', 'webcam', 'imagesearch', 'facebook', 'instagram', 'googledrive', 'dropbox', 'picasa'],
        maxFiles: 1,
        minFiles: 1,
        transformations: {
            crop: {
                force: true,
                aspectRatio: 1
            }
        },
        accept: ['image/*']
    });

    const url = result.filesUploaded[0].url;
    this.uploadedFileUrls.push(url);
}

P.S. I already checked this Filestack with Angular 2


Solution

  • Currently the parameter uploadInBackground will be set to 'true' by default, which enables background uploading. If you wish to disable this, simply insert the uploadInBackground parameter set to the value of false into your code like so:

    async showPicker() {
    
        const client = filestack.init('MyApiKey');
    
        const result = await client.pick({
            fromSources: ['local_file_system', 'webcam', 'imagesearch', 'facebook', 'instagram', 'googledrive', 'dropbox', 'picasa'],
            maxFiles: 1,
            minFiles: 1,
            uploadInBackground: false,
            transformations: {
                crop: {
                    force: true,
                    aspectRatio: 1
                }
            },
            accept: ['image/*']
        });
    
        const url = result.filesUploaded[0].url;
        this.uploadedFileUrls.push(url);
    }