Google Image Search Results

How to Add Google Image Search API to Your File Uploader

Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn

As you create any application and include a file uploader, it is important to keep in mind that every time a visitor leaves your application to find the right photo, you run the risk that he or she will get distracted and never return. You can increase your conversion rate by integrating the Google Image Search API directly into your file uploader, so users can search for and upload images without ever leaving your app. In this short demo, we will add the Google Image Search API to your file uploader with just 5 steps.

Search and Upload Images with Google Image Search API

Filestack’s file picker includes Google Image Search as well as Facebook, Instagram, Google Drive, Dropbox, image URL, and local drive as default upload sources, so your users can enjoy a fully integrated experience.

To integrate the Google Image Search into your app, simply…

  1. Sign up to get your free API key with Filestack.
  2. Add the Filestack V3 library into your code:
    <script src="https://static.filestackapi.com/v3/filestack.js"></script>
  3. Initialize Filestack using the filestack.init() function in the body of your HTML file where you would like your file picker to appear. Remember to add your own API key here.
    <script>
    const client = filestack.init('YOUR API KEY');
    </script>
  4. Run your pick function. By default image search is already included in the pick function. Optionally, you can specify fromSources: ['imagesearch'] to have Google Image Search be the only upload source:
    <script>
    client.pick({
    fromSources: ['imagesearch'],
    })
    </script>
  5. See the resulting file by running console.log
    console.log(JSON.stringify(result.filesUploaded))

Upload with Google Image Search API

Sample File Uploader with Google Image Search API

This sample code demonstrates a file uploader with Google Image Search. You can also customize your file uploader with a max number of files, max file size, specific extensions or mimetypes, other file upload sources, and more. See the file upload API documentation for more options.

<head>
   <script src="https://static.filestackapi.com/v3/filestack.js">
</script>
</head>
<body> 
   <script> client = filestack.init('YOUR API KEY');
   client.pick({  
      fromSources: [ 'local_file_system','imagesearch','facebook','instagram', 'dropbox', 'picasa', 'url'],
   }).then(function(result) {  
      console.log(JSON.stringify(result.filesUploaded)) 
   }) 
</script>
</body>

Additional Notes

By default image search will pull from wikimedia and flickr for free accounts; uploaded assets are stored in Filestack’s S3 storage and viewable in your Developer Portal. Each uploaded file returns a CDN URL, which you can use to process and deliver the file. If you are on a Starter plan or higher, you will get Google Image search results first and you can customize your cloud storage provider to add your own S3 bucket or other storage destination.

From file upload, to processing, to storage and delivery, Filestack allows you greater control and insight into your file management. Sign up for a free account to start uploading and managing files with ease.

Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn

Read More →