Wrote a plugin to parse a CSV file, have a weird timing issue

You might ask, why didn’t I just use the bubble stock File Uploader? Because I don’t want to force users to pre-edit the column headings. I’m interested in only one column, so I present them with a dropdown menu to identify which column heading identifies the column with the desired data.

The plugin does three things:

  1. Returns the number of rows in the file. I’ve created a configurable parameter which is currently set at 1000 rows, Files larger than that are not allowed at this time. This works.
  2. Returns the CSV file column headings as an array (text list). This works.
  3. Returns each row in the CSV file, one at a time.

That 3rd thing is where I’m having an issue.

Here is the workflow for after someone selects “Import”.

And here is the CURRENT workflow for a row being returned:

What happens is for every row that bubble processes, I get the URL from the last row of the CSV file.

What seems to be happening is the plugin returns rows so fast, that before bubble processes the first row, the plugin has finished returning all the rows, and the row value seen by bubble is from the last row of the CSV file, which is used for every row Bubble processes.

Unfortunately, I can’t slow down the plugin, because it uses a Javascript module named Papa Parse (which seems to be THE CSV parse module for Javascript) which runs asynchronously.

Has anyone encountered a similar problem before, and if so, how did you solve it?

Am I approaching the obtaining and processing of the individual rows wrong? Is there a better way?

I’ve made progress since yesterday and thought I would give an update for anyone in the future who tries to do what I did.

After much trial and error and liberal use of the Write to Console plugin to allow me to monitor the flow of the code, it seems when a Bubble plugin provides multiple outputs (Exposed states) in a loop, only the last one is passed to the subsequent action, but it is passed to the subsequent action as many times as there were loop iterations.

If you write a plugin that in a loop outputs 100 discreet pieces of data in a loop, it will do so, but the subsequent action in the workflow will not execute until the last piece of data is output.

Then the subsequent action will execute 100 times, using the data provided in the last loop iteration within the plugin.

So, my strategy is changing from passing out discreet data in a loop to passing out an array (List) of the data which will then be passed to a “Schedule API Workflow on a list” action.

I did bump up against another problem to overcome with that strategy, and for that I’ll submit a new topic into the forum, as it’s not specific to this issue, but is a more general issue.

Hi Kevin,

Curious to hear how your papa parse plugin turned out? Any guidance on attempting such a thing myself or is your plugin generic enough to be useful for others perhaps?

I’m trying to solve a user upload CSV problem as well. I’ve been evaluating integromat, but it’s starting to feel like a stack of 3rd parties vs something more tightly connected to the app.

It did work, with some caveats, most of which are not front of mind right now, as it’s been a while since I wrote it.

It’s not really generic.

It uses Element Actions, not Actions, which was probably a mistake, but I didn’t know any better at the time.

It has three Element Actions:

  • get_row_count: It turns out importing the CSV file is REALLY slow, so for that reason I limit imported files to 1,000 rows, so after uploading a file, I need the row count.
  • get_csv_file_column_headings: Where I parse the CSV file header row, put them into a list, and allow the user to identify which column contains what I’m interested in (the URL column).
  • get_array_of_URLs: Where I extract all the values from the URL column, and output an array/list of nothing but URLs.

From a Papaparse perspective:

  • you are downloading a file (from AWS, so the config parameter “download” must be true
  • you can not use the “beforeFirstChunk” parameter, this triggers a CORS error

If you do go this route, let’s stay in touch through this forum topic and I’ll answer whatever questions I can.

Thanks… I got integromat to work for my immediate needs. Will see how long that remains viable.