Add Data From Excel Using
Вставка
- Опубліковано 9 вер 2024
- In this episode I'm going to show you how you can add large number of data to your Directus database using #Excel and Flows.
Ok, let's do one more Directus Flow, well actually two flows that are going to work in conjunction with one another.
So imagine you have a movie database type of website, and you want to add a large number of movies to it. Currently, you have those movies stored in a Google Sheets or an Excel Document. Of course, you don't wanna do that by hand, because it will take a long time to do it.
We can use Flows for this type of scenario, we will first save our Google Sheets or Excel document to a CSV file. We are going to parse that file on the front end and create a JSON object which we will send to a Directus Webhook, that will in turn trigger our first Flow. Since we are receiving an array of objects we can create a kind of for each loop by triggering another Flow for every object in that array. That other Flow is just simply going to add the data from the object it receives to the Movie collection.
Ok, so let's do this.
Code used in this video
bit.ly/3G4hW87
You can support my work on Patreon
/ watchlearn
Follow me on Social Media
Github: github.com/iva...
Twitter: / ivan_doric
Thanks
Thanks for the tip man 😄
Please more flows
Amazing, i will be doing something very similar.
Apart from parsing in the format we want, what is the advantage of this example compared to the built in CSV importer of Directus?
This is just an example of what Directus can do. Of course if importing CSV makes more sense you should use that.
@@WatchandLearnTutorials Indeed, the default CSV is useful but not very flexible, doing it with Flows gives much more control and results in cleaner Excel sheets.
sir i have payload of millions records how i can add it, which have foreign contains too, in minimum time;
How do you iterate over arrays? or the flow does it automatically?
I don't know React, but isn't useEffect triggered with each element that is added to moviesList? And therefore there are 5 calls to the webhook?
UPDATE:
Actually it is explained at 4:05ff: When data is delivered as an array than the flow triggers the other flow on each item. Seems as if the loop is built-in to the first flow...
@@RobertWildling @WatchandLearnTutorials - I am actually doing exactly the same thing - passing an array to the 2nd flow. But it fails with 'undefined'. I tried many different JSON payloads, but it always seems to get the full array, not iterating over the array.
Great Example, thank you very much! - Unfortunately I get a CORS error as soon as I upload the csv file. Tried to add CORS to Directus' .env file, but no changes. Do I have to change the headers in the React App? Or what do I have to do?
I just tried "mode:'no-cors" on the fetch method, but then I get the weird console error "add-movie.jsx:34 Error: SyntaxError: Unexpected end of input (at add-movie.jsx:29:38)"
Hmmm, what version of Node are you using?
do we need to sanitize the data?
How to update a collection using webhook
discord