How do you use the FileUploader input form to allow a user to upload a csv file

I want to allow a user to upload a csv file and have the data in the csv file added to the data type fileds in the app data. I used the FileUploader and when i run it, it only moves the file to the file manager. How do i get this to automatically move into the app data?


When you upload a file through the File Uploader, Bubble automatically stores this file in the File Manager (you can schedule a workflow to delete this file later if desired). And if you’ve set up the ‘Upload data as CSV’ action in the ‘Workflow FileUploader’s value is changed’ and the CSV is properly formatted, it should also automatically insert the data into the database.

Verify that the CSV is correct - the headers must exactly match the field names in the Investments table in Bubble.

When i upload it manually through App Data, it does ask me to map a couple fields. The fields are user, which i have to set to email, category i have to set to type, and list name to list name. Is there a way to set up the upload to automatically do those mapping? It looks like the data was put in just without those fields.

Also i had gone through and made sure the headers are exactly as they are in the field names.

It seems you’re having issues parsing CSV data into your database. This is happening because your table likely has fields with data types that aren’t text-based, so Bubble can’t insert the data correctly since CSV only provides text-type data.

One solution is to create a new table with all desired fields set to text data type. Then, you would need to run a recursive or scheduled backend workflow on a list to parse this data and insert it into your original table. For example, to populate the user field, you would do a search for user > email = email (from CSV) > first item, and so on for other fields.

There might be an easier way to accomplish this, but this is the approach I’m familiar with.

How do you do a backend workflow for this? I have not used backend workflows yet.

I would do something like this:

I would create 2 backend workflows, e.g.: import_csv_step1 and import_csv_step2

In import_csv_step1, two actions:
1 - Upload data as CSV (where I would import the CSV items to the auxiliary table, with all fields as text type)
2 - Schedule API Workflow import_csv_step2 on a list

Image

In import_csv_step2 I would do the parsing, creating the items in the original table.

Image

In the frontend you need to send the CSV file via parameter to run import_csv_step1.

Image

Here I created a similar flow in a very simplified way for you to see how it works. If you’ve never worked with backend workflows, you might find it a bit complicated, but it will be a good exercise for training.

Hi Ruiz,

I seem to be having a little problem with this because i am very new to it. I am going to provide screenshots of where i am at trying to follow your steps.


This screenshot above is of the data type Investments which is where i want to data to end up at.

The above screenshot is the data type i create to have all the fields a text field.


The above screenshot shows that the upload data as csv does not allow me to select the file uploader.


This one above i am getting lost at how to set this up properly

In this image, you need the CSV to be of the file type, as you’ll be sending the CSV file to the backend.

Image

https://us1.discourse-cdn.com/bubble/original/3X/c/e/cee1d1d57680d7ba91b60618be1066f876821cdb.png

For step 2, you need to set the file type as CSV Investments and also leave the list box unchecked. This will pass one item at a time to step 2, allowing you to work on parsing items individually.

Think of it as passing a list of CSV Investments, but in step 2, you receive them one at a time in sequence. You’ll receive item #1 and create a corresponding Investment, then item #2 and create that item, and so on…

i think i have the first step correct now.




for step import_csv_step 2, I am not seeing where i can search each item in the CSV investments

Now you need to parse the data. It’s difficult for me to fully guide you through this here, but basically for text fields, you’ll simply copy what came in the CSV. For numeric fields, copy the text from the CSV and select “convert to number” - in these cases, select Workflow Data Source > csv and copy the text from there to the field you want to fill. For fields related to other tables or option sets, you’ll need to find that item in your database using the CSV text. That’s why the suggestion is to use “Do a Search for” and use constraints to filter and select the data you need to populate your investment table. In the image you posted of your table, you’ll only need to use “Do a Search for” on the Category field. There might be other relational fields further down, but from what you showed in the photo, only that one would use “Do a Search for…”

here is the full list screenshot


for text fields i was able to type in how it is in the CSV. So for Ticker = (i just typed in Ticker which is exactly the header in the CSV file) When i do that, it only sends to the Investments data type app data the name i typed in for each investment and not its actual ticker. For number fields, it wont let me type in at all. for category, it is in the screen shot below

Ive tried a few different ways to put them in


There’s something wrong with the setup of your workflow step 2, you’re sending the file URL to step 2 and not the investment imported by the csv. You should be able to pull fields from the CSV Investments table, as in my example here, in which I can pull any field from the “contato” table.

Perfect, i was able to update that per below screenshots




Now just trying to get the fields that are category type, investments list, list name, user, type

Alright i have most of it working. The only two i cant get to work is Type which is an option set
and List name which is an investment list field



For the option set you’ll need to do something like this:

Image

Image

Image

As for the List name, it should be working the way you did it, even though it turned yellow. I believe it’s just a Bubble bug, because it seems like you did it correctly.

Thanks Ruiz for everything! i was able to get everything to work perfectly with your help!

1 Like

I’m glad it worked out well!