Site icon Filestack Blog

File Picker V3 in Action

Filestack has recently launched our File Picker V3 with a minimalistic design, in-app image transformations, and an even faster file uploading API.  In case you missed it, you can read more about the new features and improvements in our article Filestack Launches File Picker V3.

The new UI is what everyone needs in a modern website. Uploading a file has never been so easy and fast as it is now, and we finally released the library as npm for the node ecosystem. Also, after many user requests, there is now an pro plan for the first time which means you can upload an unlimited number of files!

I have already experimented with the new picker and I can honestly say I have been quite surprised by it. I didn’t realize it was possible, but the Filestack engineers managed to make the new integration even easier than before:

 

In-App Transformations

As the documentation makes it clear, we are able to apply a few transformations within the uploader UI. Here is the list of the available transformations: minDimensions, maxDimensions, crop, rotate, circle, monochrome, sepia. The pick function’s new property transformOptions accepts a boolean value to enable them:

{ transformOptions: { { parameter: value } }

Where parameter is the targeted transformation.

The App

For the purpose of the article I wrote a very simple html/javascript page served by json-server:

Users can upload and edit their photos before seeing them in the browser. As always, you can clone/fork the repo on my github profile.

To use Filestack API we need to set our API key, init is the function we need:

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

Now we can access the entire API and call pick.

But let’s not set some real-world restrictions on our users:

Here is the customized pick function:

client.pick(
  {
    accept: 'image/*',
    maxSize: 1024 * 1024 * 2,
    transformOptions: {
      transformations: {
        rotate: true,
        circle: true,
        monochrome: true,
        sepia: true,
        crop: {
          aspectRatio: 16/9,
        },
      }
    }
  }
)
.then(function(data) {
  document.getElementById('filestack-pic').src = data.filesUploaded[0].url;
  console.log(JSON.stringify(data.filesUploaded))
});

The new pick function returns a promise and once it resolves it provides the CDN url for the photo:

data.filesUploaded[0].url

data.filesUploaded is an array since we can upload more than a picture but the default behavior only allows one picture to be uploaded at a time. In our case, we simply take the first and only photo from it.

Moreover, the new API now returns the handle so we can now get it by writing:

data.filesUploaded[0].handle

And that’s pretty much all we need to write.

Upload Example

Now, let’s say we want to upload a photo of the “handsome” Darth Vader:

Thanks to the new pick function we can create a cool avatar picture out of it, take a look at the result:

I applied the monochrome and circle transformations to the picture.

First, upload the picture:

And then edit it to apply monochrome and circle:

…And this is just the beginning!

What we have seen today is just an introduction to file picker V3, stay tuned for more.

Exit mobile version