Copying files from DropBox to IBM Cloud Object Storage on schedule
Learn how to use IBM® App Connect to create an event-driven flow that copies files weekly from a Dropbox folder to a new bucket in IBM Cloud® Object Storage.
IBM Cloud Object Storage S3 can hold large amounts of production data, such as backups and archives, and large individual files, such as video files, image files, and genomic data. IBM Cloud Object Storage S3 provides reliable, durable, and resilient object storage.
Scenario
You use Dropbox to share files in folders specific to users. Once a week, on a defined schedule, you want to copy the files from a shared folder in Dropbox to a new bucket in IBM Cloud Object Storage S3. The new bucket is given a name based on the date that the files were copied.
Find or create what you need
- You can create a connection to Dropbox either by using a Dropbox user ID and password or by using a Google account.
- To connect to an IBM Cloud Object Storage account,
you need the following values that can get from the "Endpoint" and "Service Credentials" pages in
the side navigation of your IBM Cloud Object Storage
dashboard:
- Endpoint URL: Cloud Object Storage Endpoint / PUBLIC or PRIVATE URL value for your region; for example, s3.us.cloud-object-storage.appdomain.cloud (PUBLIC for us-geo region)
- Secret Access Key: Cloud Object Storage Service credentials / View credential (with HMAC) / cos_hmac_keys/ secret_access_key
- Access Key ID: Cloud Object Storage Service credentials / View credential (with HMAC) / cos_hmac_keys / access_key_id
- Region: Cloud Object Storage Endpoint / Select Location value; for example, us-geo
Note: To get a Secret Access key and Access Key ID, you need to first create a credential with the option to generate HMAC credentials. (When you add a credential, specify{"HMAC":true}
in the Add Inline Configuration Parameters (Optional) field.For more information, see Service credentials in the IBM Cloud Object Storage documentation.
Create your flow
Create your flow from a template, or from scratch if you want to explore how to create a flow.
Creating the flow from a template
If you use a template, you can create the flow immediately, then select each node in the flow to validate the node and select the application accounts that you want to use. Search for the template name on the Templates tab.
The template name is "Weekly copy Dropbox files to new Cloud Object Storage S3 bucket named with date".
To continue with the template, see the template instructions in Github (opens in a new window)
After you create a flow from the template, you can continue to test your flow.
Creating the flow from scratch
- On the catalog tab, connect App Connect to your Dropbox and IBM Cloud Object Storage accounts. (You can also connect to
applications in the flow editor.)
The following steps assume that you used the catalog to connect App Connect to your Eventbrite, Sharepoint, and Slack accounts.
- From the Designer dashboard, click .
Complete the following steps. As you progress, App Connect automatically saves your changes. If you move away from the flow at any stage, the flow is saved as a draft flow that you can complete at another time.
- Enter a name that identifies the purpose of your flow; for example: Weekly copy Dropbox files to new COS S3 bucket named with date.
- Configure a scheduler as the event that is to trigger the flow once a week. In this example, the flow runs every week, on Friday at 8 PM GMT. To test the flow, you can set the flow to run when it is first started.
- Click the Toolbox tab to open the Toolbox.
- Click Scheduler.
- Click Select schedule type and select the Calendar option.
- Set the Run every options to Week on FRI at 20:00.
- Set Timezone to Etc/GMT.
- Select Also run the flow when it's first switched on.
- Click the (+) and then scroll down to Dropbox.
- Select
Actions on folders or files in Dropbox are by ID, which is equivalent to the file name. The "Retrieve all folders" action returns details of all folders (as a JSON object) so that App Connect can map from a folder name to its ID.
If your Dropbox account has more than 10 folders, configure the Maximum number of items to retrieve option. You can also change the options if the maximum number of items (folders) is exceeded, or if no items are found.
as the action. - Use a variable of path_lower"="/shared to handle the ID of the one folder
that you want to process. (You don't need to use a variable, but a variable with a meaningful name
can be useful instead of using a property reference and expression in multiple places.)
- Click Add node (+), then open the Toolbox tab.
- Select Set variable.
- Click Add property and enter the name FolderID.
- Click Edit mappings, then map the ID field from the Dropbox "Retrieve
folders" action. For example, type id, then select ID
from under foldercollection.
The "Retrieve folders" action returns an array of data for one or more folders (as indicated by the message under the FolderID field). Therefore, use a JSONata function to get the ID of the folder with the path_lower"="/shared variable.
- In the FolderID field, click the ID mapping, and from the menu, click
Edit expression. This field shows the JSONata expression that is used to get
ID values for all folders as an array.
{{$DropboxRetrieveallfolders.id}}
To restrict the data to the folder with the path_lower"="/shared variable, change the expression to the following example.{{$DropboxRetrieveallfolders[path_lower="/shared"].id}}
- Click Add node (+), then scroll down to Dropbox, to add the action to retrieve all the files in the folder to be processed.
- Select as the action.
- Filter the action to get files from the folder with the ID that you identified previously.
- Click Add condition.
- Click in the field after equals, then type folderif.
- From the menu that opens, select the variable FolderID.
- Click Add node (+), then scroll down to IBM Cloud Object Storage S3.
- Select Configure the action as follows.
- Click in the Bucket name field.
- Click the Insert a function icon.
- From under Date/time functions, select $now().
- Configure the
$now()
function and add text or field mappings for the name that you want to use for the Cloud Object Storage S3 bucket. The following example adds text and edits the$now()
function to change the format of the date in the bucket name.dearliza-{{$now('[Y0001]-[M01]-[D01]') }}
For more information, see the JSONata documentation.
as the action to create a bucket that is based on the date when the
action is completed. - Add a For each loop to process each file from the Dropbox Retrieve all files action.
- Click Add node (+), then open the Toolbox tab.
- Select For each.
- Click in the Select the collection of items to process field.
- Type filecoll, then from the menu that opens, click
filecollection from under the Retrieve files action.
Use the default values of the options to process all items (files) in the collection sequentially and to continue processing other files if an error occurs during file processing.
- In the For each node, configure what happens for each Dropbox file. This example adds an If node to take different actions that depend on the suffix of the Dropbox file. (Dropbox doesn't provide different Content-Type values for different types of files.)
- If a file name contains
.mp3
or.pdf
, handle this file as a binary file.- Use the Dropbox Download file content action to get the content of this file by using its file path and a file type of binary.
- Use the IBM Cloud Object Storage S3 Create object action to create an object in the selected bucket with the file name of this file and the content from Dropbox.
- If a file name doesn't contain
.mp3
or.pdf
, handle the file as a text file.- Use the Dropbox Download file content action to get the content of this file by using its file path and a file type of text.
- Use the IBM Cloud Object Storage S3 Create object action to create an object in the selected bucket with the file name of this file and the content from Dropbox. Set the content-type to text/plain.
- In the For each node, click Add node (+), click the Toolbox tab, and then click If (conditional).
- In the if field, type
name
, then select Name from under filecollection. - Click Name, then select Apply a function.
- From under String functions, select $contains.
- In the $contains expression, change the missing
chars
with.mp3
. This value completes the expression as follows.{{$contains($Foreachitem.name, ".mp3")}}
(You can paste this string into the if field.)
- Change the equals condition to an is true condition.
- Add another condition for .pdf files. Click Add
condition, then use the same steps as for .mp3 files. For example,
add the following expression.
{{$contains($Foreachitem.name, ".pdf")}}
- Next to the if label, change the condition to Any of the following are true.
- If a file name contains
- Configure the actions for the If branch of the For each node.
- In the If branch of the For each node, click Add node (+).
- Scroll down to Dropbox and select .
- Click in the Path field, type
path
, then select Path lower from under For each … filecollection. - Set File Type to Binary.
- In the If branch of the For each node, click the next Add node (+) icon.
- Scroll down to IBM Cloud Object Storage S3 and select .
- Configure the Create object action.
- Bucket: Typically, you select an existing bucket from the list, but for
this flow, you need to specify a bucket that doesn't yet exist. To specify this bucket, use advanced
mode.
- Click the Map options menu (⋮) and select Switch to advanced mode.
- Click in the Bucket field and enter the same name that you used on the
Create bucket action. (You can copy the value from the Bucket name field of
that action).
dearliza-{{$now('[Y0001]-[M01]-[D01]') }}
- Object name: Click in the field and insert a mapping to the value.
- Object content: Click in the field and insert a mapping to the value.
- Leave the Content type field empty.
- Bucket: Typically, you select an existing bucket from the list, but for
this flow, you need to specify a bucket that doesn't yet exist. To specify this bucket, use advanced
mode.
- Configure the actions for the Else branch of the For each node.
- In the If branch of the For each node, click Add node (+).
- Scroll down to Dropbox and select Download file content.
- Click in the Path field, type
path
, then select Path lower from under For each … filecollection. - Set the File Type to Text.
- Click the next Add node (+) icon in the If branch of the For each node.
- Scroll down to IBM Cloud Object Storage S3 and select .
- Configure the Create object action.
- Bucket: Typically, you select an existing bucket from the list, but for
this flow, you need to specify a bucket that doesn't yet exist. To specify this bucket, use advanced
mode.
- Click the Map options menu (⋮) and select Switch to advanced mode.
- Click in the Bucket field and enter the same name that you used on the
Create bucket action. (You can copy the value from the Bucket name field of
that action.
dearliza-{{$now('[Y0001]-[M01]-[D01]') }}
- Object name: Click in the field and insert a mapping to the value.
- Object content: Click in the field and insert a mapping to the ' value. (Make sure that you select File content for the Download file content action on the Else branch.)
- Set the Content type to text/plain.
- Bucket: Typically, you select an existing bucket from the list, but for
this flow, you need to specify a bucket that doesn't yet exist. To specify this bucket, use advanced
mode.
Test your flow
- Click Start flow on the toolbar, then click
Dashboard to exit the flow. Check the flow tile on your Designer dashboard to
see whether your flow is running successfully (the flow tile shows a green tick after a short time).
If your flow fails to run successfully, check the log for messages and take appropriate action.
- Log in to your IBM Cloud Object S3 instance and check for the new bucket and for the files that were copied from Dropbox.
Conclusion
You created a flow so that on a weekly schedule, files are copied automatically from a Dropbox folder to a new bucket in IBM Cloud Object Storage.