Created
August 10, 2018 01:23
-
-
Save godie007/d66f0dffdb1fa6af623758035060c6dc to your computer and use it in GitHub Desktop.
subir archivos csv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| script(src='/views/js/jquery.min.js') | |
| script(src='/js/bootstrap.min.js') | |
| script(src='/js/cargue.js') | |
| script(src='/vendor/bootstrap/js/dropdown.js') | |
| block body | |
| div.page-header | |
| div.col-sm-11 | |
| div(id="usuario", class="#{usuario}") | |
| form.form-horizontal | |
| br | |
| .control-group | |
| form.control-group#uploadForm(enctype='multipart/form-data', action='/admin/area/migrar', method='post') | |
| input(type='file', name='userPhoto') | |
| br | |
| input.btn.btn-primary(type='submit', value='Importar', name='submit') | |
| div#status | |
| script(type='text/javascript', src='/vendor/jquery/jquery.js') | |
| script(type='text/javascript', src='/views/js/jquery.form.js') | |
| script. | |
| $(document).ready(function() { | |
| $('#uploadForm').submit(function() { | |
| if ($("input[name='userPhoto']").val() ==='') { | |
| toastr.options = { | |
| closeButton: true, | |
| debug: false, | |
| newestOnTop: false, | |
| progressBar: true, | |
| positionClass: "toast-top-center" || 'toast-top-right', | |
| preventDuplicates: false, | |
| timeOut: "1000", | |
| onclick:null | |
| }; | |
| toastr.error("Debe seleccionar un archivo en formato CSV.", "Importante!"); | |
| }else{ | |
| var formData = new FormData($(this)[0]); | |
| formData.append("titulo", $("#titulo").val()); | |
| formData.append("usuario", $("#usuario").attr("class")); | |
| $.ajax({ | |
| url: '/admin/area/migrar', | |
| type: 'POST', | |
| data: formData, | |
| async: true, | |
| success: function (data) { | |
| $("#status").html(data); | |
| $("#uploadForm").hide(); | |
| }, | |
| cache: false, | |
| contentType: false, | |
| processData: false | |
| }); | |
| } | |
| return false; | |
| }); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // dependencias | |
| var Converter = require('csvtojson').Converter | |
| var fs = require('fs') | |
| var formidable = require('formidable') | |
| // codigo del controlador | |
| exports.subir = (req, res, modulo) => { | |
| var form = new formidable.IncomingForm() | |
| form.parse(req, (err, fields, files) => { | |
| var csvConverter = new Converter({}) | |
| csvConverter.on('end_parsed', (jsonObj) => { | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment