How To: Upload a file to Google Drive with a SmartForm

In this article, you use the Google Drive File SmartObject to upload a file to your Google Drive. This File SmartObject and others are created for each cloud storage feature you activate. These features allow you to integrate K2 with Dropbox, Box, Google Drive, and OneDrive using SmartObjects, and then use these SmartObjects in your K2 solutions. For more information about the cloud storage service type and creating service instances, see Cloud Storage

Using a SmartForm to upload a file to Google Drive

Scenario

Your company uses an online form for customers to request warranty repairs. As part of your form, you want your customers to upload an image showing their damaged item. You need this image uploaded to Google Drive so that your repair engineers can access it.

Steps

In this scenario, you use the Google Drive File SmartObject to create an item view. In the item view, you configure the Upload method with the Path and File parameters.

Setup Steps

The following steps set up the scenario. If you want to skip the setup steps and view the topic step, go to Create a new view using your Google Drive File SmartObject.

  1. Activate the Google Drive feature
    1. See Google Drive Feature Activation for configuration steps

Create a view using the Upload Method

Create and configure a view using the Upload method of the Google Drive File SmartObject. In this scenario, customers upload an image to the Denallix folder.

  1. Create a new view using your Google Drive File SmartObject.
    1. In K2 Designer, navigate to your folder in the Cloud StorageGoogle Drive folder (this name is based on the name you specified during Google Drive feature activation), right click your File SmartObject, and select Design View. If you are not familiar with creating views, see How To: Create an Item View and a List View.
    2. Name the view GoogleDrive_Upload_View.
    3. Select a Category for the view. In this example, the category containing the SmartObject is used.
    4. Select Item View.
    5. Click Create to start creating the view.
  2. Configure your view to use the Upload method with the Path and File properties.
    1. Select Create Labels and Controls.
    2. Select to include Path and File layout field names and check the Upload method in the Standard button column.
    3. Your view looks similar to the following image:
  3. Create a new form using your GoogleDrive_Upload_View.
    1. On the GoogleDrive_Upload_View page, select Design a new Form. If you are not familiar with creating forms, see How To: Create a Form.
    2. Specify GoogleDrive_Upload_Form as the Name and Cloud Storage upload for Google Drive as the Description.
    3. Click Create.
    4. Click Finish to save your form.
  4. Test your form by uploading an image to Google Drive
    1. On the GoogleDrive_Upload_Form page in K2 Designer, click Run.
    2. Drag your image onto the File control and specify the Path (you must include the file name and extension of the file in the Path property). In this scenario, you upload a file named repair_needed.jpg to the Denallix folder. Note that you may want to create a rule to change the name of the file before uploading it to Google Drive.
    3. Go to your Denallix folder in Google Drive and confirm that the image is uploaded.
Review

You used the Upload method of the Google Drive File SmartObject to upload an image to a Google Drive folder.