Dittofi
  • Tutorials
    • Tutorial Index
    • Quick Start
    • Dittofi Essentials
      • Part 1: Frontend terms and concepts
      • Part 2: Backend terms and concepts
      • Part 3: Connecting frontend and backend
      • Part 4: Dittofi app structure
    • Dittofi App Design
      • 🏗️App architecture 101
      • ◼️Backend app development 101
      • 🟪Frontend app development 101
      • 🔰(optional) Web developer beginner series
  • Learn Frontend
    • 👨‍💻Getting Started
      • Welcome to Dittofi
      • Intro to the Dittofi Design Studio (Frontend)
    • 🟩Pages
    • 🟪Elements
      • Types
        • Button Element
        • Div Block Element
        • Form Block Element
        • Link Block Element
        • List Element
        • Modal Box Element
        • Tabs Element
        • Columns Element
        • Image Element
      • Partials
      • Prefabs
      • Custom
    • 🟧Variables
      • Array
      • Checkbox
      • Collection
      • Collection (Custom Model)
      • Collection (System Custom Model)
      • Custom Model
      • Date
      • Datetime
      • File
      • Json
      • Number
      • Number with decimal
      • Model
      • System Custom Model
      • Text
      • UUID
    • 🟨Events
      • 🟨External
        • HTTP Request
        • Run Endpoint
      • 🟨Flow Control
        • Condition
        • Run Action
        • Loop
        • Sleep
      • 🟨Maths
        • Add
        • Divide
        • Modulus
        • Multiply
        • Subtract
      • 🟨Navigation
        • Open Page
      • 🟨Notifications
        • Alert
        • Confirm
      • 🟨Other
        • Copy To Clipboard
        • Run Custom
      • 🟨Text
        • Concat
        • Contains
        • Ends With
        • I Contains
        • I Ends With
        • I Starts With
        • LTrim
        • RTrim
        • Text To Upper
        • Text To Lower
        • Trim
        • Starts With
      • 🟨Variables
        • Set Field
        • Remove Field
      • Validate
    • 🟦CSS Layouts
      • Holy Grail Layout
      • Side Bar Layout
      • Sticky Footer Layout
      • Sticky Header Layout
      • CSS Frameworks
    • 🔲CSS Frameworks
    • Component Libraries
    • Meta Attributes
  • Learn Backend
    • 🖥️Getting Started
      • Intro to Data
      • Intro to APIs
      • Build your first custom API
      • Actions & Events
    • 🟫Back-End Actions
    • 🟩Custom Models
      • 🟩Attributes
        • Array
        • Checkbox
        • Custom Model
        • Collection (Custom Model)
        • Collection (System Custom Model)
        • Date
        • Datetime
        • File
        • Number
        • Number With Decimal
        • Json
        • Text
    • ◼️Data Models
      • Database Fundamentals
        • Database relationships
      • ◼️Columns
        • Attachment
        • Auto Increment
        • Checkbox
        • Date
        • Datetime
        • Duration
        • Email
        • Long text
        • Link to another record field
        • Number
        • Number with decimal
        • Password
        • Phone number
        • Percent
        • Price
        • Rating
        • Single select
        • Single line text
        • URL
    • 🟥Events
      • 🟦Arrays
        • Append
        • Array Pop
        • At
        • Length
        • Prepend
        • Range
      • 🟦Conversions
        • Base64 Encode
        • Base64 Decode
        • Json Decode
        • Json Encode
        • Path Escape
        • Path Unescape
        • Query Escape
        • Query String Parse
        • Query Unescape
        • To Bool
        • To Float
        • To Int
        • To Str
        • Yaml Encode
        • Yaml Decode
      • 🟦Database Requests
        • Create
        • Create Or Update
        • Delete
        • Has Record
        • Read Event
        • Update
      • 🟦External
        • HTTP Request
        • SFTP Download
        • SFTP Upload
      • 🟦Files
        • CSV Reader Event
        • CSV Writer Event
        • File Read
        • File Save
        • File Size
        • File Type
        • JSON Reader
        • PDF Generator
      • 🟦Flow Control
        • Condition
        • Loop
        • Return
        • Run Action
        • Sleep
      • 🟦Notifications
        • Send Mail
        • Connect Websocket
        • Message Websocket
      • 🟦Maths
        • Add
        • Acos
        • Acosh
        • Asin
        • Asinh
        • Atan
        • Atanh
        • Cbrt
        • Ceil
        • Divide
        • Modulus
        • Multiply
        • Subtract
      • 🟦Security
        • Compare Password
        • JWT Decode
        • JWT Encode
        • Login
        • Logout Web User
        • Password Generator
        • Random Number
      • 🟦Time
        • Add Time
        • Day
        • Format Time
        • Minute
        • Nanosecond
        • Parse Time
        • Second
        • Time In
        • Year
        • Year Day
      • 🟦Text
        • Concat
        • Contains
        • Ends With
        • Execute Template
        • I Contains
        • I Ends With
        • I Starts With
        • Starts With
        • LTrim
        • RTrim
        • Replace
        • Regex Find All String
        • Regex Find String
        • Regex Match String
        • Trim
        • Text To Lower
        • Text To Upper
        • Text To Title
        • Url Getarg
      • 🟦Other
        • Assign
        • Run Custom
        • Redirect Web Page Event
        • Render Web Template Event
    • 🟧Variables
      • Array
      • Checkbox
      • Collection
      • Collection (Custom Model)
      • Collection (System Custom Model)
      • Custom Model
      • Date
      • Datetime
      • File
      • Json
      • Number
      • Number with decimal
      • Model
      • System Custom Model
      • Text
      • UUID
    • 🟪Webservices
  • Templates
    • Two sided marketplace template
      • Introduction
        • Part I: Installing and setting up the marketplace template
        • Part II: Understanding what features are included in the marketplace template
        • Part III: Customizing your marketplace frontend without coding
        • Exploring Dittofi's marketplace API
      • Listings
        • How to create a marketplace listing
    • How to build a CRUD app
  • Third Party APIs
    • OAuth 2.0 APIs
      • Introduction To OAuth 2.0
      • Google OAuth 2.0 - PART I
      • Google OAuth 2.0 - PART II
  • Dittofi Admin
    • Your Account
      • Workspace Admin
      • Manage Billing
      • Connect a custom domain
      • How to use a discount code to Dittofi Pro
  • FAQ
    • API Generator
    • How to write custom SQL?
    • Why does my image not display?
    • How can I set up Google Analytics?
    • Exporting and deploying my frontend code
    • What is a partial and what is a prefab?
    • How to set up a basic mulit tenant app on Dittofi
    • How to write a custom endpoint in Dittofi
    • How to integrate Font Awesome into Dittofi
    • How can I set up Dittofi to run on my own private server?
    • How to add roles such as Super Admin, Admin, Manager & User
    • How to prevent duplicate records being added to the database
    • What to do when relation cannot be created because their is violating data in the referenced table
  • Change Logs
    • Dittofi Change Logs
Powered by GitBook
On this page
  • Step 1. create a custom model
  • Step 2. create a CSV reader endpoint
  • Step 3. create a CSV reader action
  • Step 4. Add the CSV reader event
  • Step 5. build and test your code
  • Step 6. looping through the CSV data

Was this helpful?

  1. Learn Backend
  2. Events
  3. Files

CSV Reader Event

An overview of how to configure the CSV Reader event in Dittofi

PreviousFilesNextCSV Writer Event

Last updated 3 years ago

Was this helpful?

The CSV reader event lets you build in functionality to import custom CSV files into your apps. You can set up the CSV reader event in five quick and easy steps.

  • Step 1. create a custom model

  • Step 2. create an csv reader endpoint

  • Step 3. create a csv reader action

  • Step 4. add the csv reader event

  • Step 5. build and test your code

  • Step 6. looping through the CSV data

For the purpose of this example, we will be using the CSV file below.

Step 1. create a custom model

To use the CSV reader event, you first need to head over to the custom models tab. You can find the custom models tab under the wrench icon in the Dittofi Design Studio.

Create a custom model with the custom attributes set to the same names as the CSV headers i.e. address_line_1, address_line_2 and postcode. See below.

TWO IMPORTANT THINGS TO NOTE:

  1. When you create the Custom Attributes we set the type to Text. If you want to configure your app to import different data types, you need to set these data types. For example, if you want to import numbers, you need to set the data type to Number.

  2. When you set the Custom Attributes, you need to choose between strict and nullable options. The nullable option allows you to import null values into the field. The strict option will force your system only accept the row of data if the field is not null.

Step 2. create a CSV reader endpoint

You can create your CSV reader endpoint from within the endpoint tab. Set up the endpoint with the name "CSV Reader", the path "/v1/csv_reader", the description "Read in my address book", the request method to "Post" and the req content type to "multipart/form-data". You can see an example of this below.

Next, you need to add a body variable to your endpoint. This will allow your endpoint to accept the file that you're expecting to upload. You can set the name to "uploadfile" and set the type to "file", as below.

Step 3. create a CSV reader action

Next up, head on over to the actions tab and create a CSV reader action called CSV Reader and link this action to your endpoint.

Step 4. Add the CSV reader event

Next, add the CSV reader event to your action and pick the file that is being passed in from your endpoint. Set the Single Row As option to use the custom model from step 1. This Single Row As variable is going to hold one row of data that is being looped over by the event. Lastly, set the All Rows As to AllRows. The All Rows As variable holds all the data that is being uploaded by the file in memory. The All Rows As variable is populated one row at a time as the file that has been uploaded is being looped over.

Finally, go to the action trigger and set the response variable to "AllRows". This will send all the rows of data that are being uploaded back to your endpoint. This can be useful if you want to display this data immediately in your frontend.

Step 5. build and test your code

To build your code, click the "Build code" button and wait for the code to build. Once the code has been built, open up your CSV reader endpoint and click the run button. Using the body variable input, select the test CSV file and click run.

You will notice that the response variable from your CSV reader action, "AllRows", is displayed in your endpoint. This is the same data that is in your CSV file upload.

Now that you know how to use the CSV Reader event, you can combine this event with different events and workflows to do all kinds of things with your data. You can, for example, display the data in the front end of your app, extend the action to map this data into a Data Model and much much more.

Step 6. looping through the CSV data

Notice, you can also loop through the CSV data and map this data into one of your Data Models. To do this, create a Data Model to store the data.

Next, head on over to the actions tab and open up the CSV reader action that we created in step 3.

Add a Loop Event to iterate over the CSV data stored inside the AllRows variable.

Next add a Create Event inside the loop event. This will be used to write each row of data that is iterated over to your Data Model.

Finally, map the RowOfData to the columns in your data model.

Notice, you can do anything in the loop such as send emails to everyone in the csv file if you have a list of emails in your file.

Get the sample file .

🟥
🟦
here