Upload CSV to Keystone Database
See original GitHub issueI am trying to upload a csv file via an upload button in Keystone Admin UI to insert the content of the CSV file into the mongodb database.
For example, I have a blog post CSV file and I want to upload it to the Post table in the Keystonejs database.
Such upload button does not exist so I have to create one beside the existing Create Post button.
Also I have to make some csv to mongodb logic code and put it to somewhere.
I am hoping someone here using Keystone can give me a bit direction on how to implement this upload button and update mongodb logic as in where/which file to put the code?
To me right now, it looks like the path /node_modules/keyston/admin/src/views
is the place to go. Am I right?
Issue Analytics
- State:
- Created 8 years ago
- Comments:15 (4 by maintainers)
Top Results From Across the Web
CSV Import · Issue #150 · keystonejs/keystone-classic - GitHub
Ok, we have CSV Export and Download, how about CSV Import? I'm working on a rewrite of a small local website and am...
Read more >How to upload a file to KeystoneJS server - Stack Overflow
I'm trying to upload a csv file to KeystoneJS (I want to parse the rows and add the records to my MongoDB), but...
Read more >Keystone CSV File Specification
Employer Earned Income Tax (EIT) Upload. Comma-separated (.CSV) File Format. USE COMMAS AS FIELD SEPARATORS ONLY. DO NOT USE COMMAS WITHIN A DATA...
Read more >Keystone Js | Excellence Technologies
For download or export of the saved data stored in database, keystone provide a method getCSVData . that's allow which field should include...
Read more >LOAD a CSV - Vertica Forum
I have a problem when I want to load one .csv file, I did this STEP 1 create table prueba(Id VARCHAR(100),Sepal_Length FLOAT,Sepal_Width ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Finally I got it done. (It will delete the original list data though, you are warned)
I hope my work can help someone who want this CSV upload feature.
Here is the code/meat/HowTo:
modify the
keystone/admin/src/views/list.js
, I am ONLY allow upload csv forPost
list, you can use your own list.Add a new
UploadForm
by createkeystone/admin/src/components/UploadForm.js
, please note the form submit action can be customized, mine is/uploadcsv_post
.Continue to add
/uploadcsv_post
logic to keystone route, createroutes/api/uploadcsv.js
, please note that I added my own customized json parser to suit my own CSV file format, you should modify it to suit your needs.Don’t forget to change the route at
routes/index.js
with below code:Also install
csvtojson
:I hope someone can use it or even better, integrate this feature into Keystone.js.
@xianlin , you could reduce your csv to json with the ff code