Replies: 2 comments 7 replies
-
Hi @thiagow Short answer - no, there's currently no component for reading and displaying the contents of a CSV file within a client app. In the meantime, if you have access to AWS I tried out this solution with Lambdas that works ok. Step 1- Add S3 Bucket Upload ComponentCreate a new S3 datasource: Add a form with an S3 File Upload component Step 2 - AWS LambdaCreate a new node project on your computer, and install the csvtojson library. There's a guide in this StackOverflow answer: https://stackoverflow.com/questions/59590490/aws-lamda-cannot-find-module-csvtojson Add a new handler.js file to the root of the project with the following JavaScript: const csv = require('csvtojson')
const aws = require('aws-sdk');
const s3 = new aws.S3({ apiVersion: '2006-03-01' });
exports.handler = async (event) => {
//console.log('Received event:', JSON.stringify(event, null, 2));
// Get the object from the event and show its content type
let bucket = "";
let key = "";
if (event.queryStringParameters && event.queryStringParameters.bucket) {
bucket = event.queryStringParameters.bucket;
}
if (event.queryStringParameters && event.queryStringParameters.key) {
key = event.queryStringParameters.key;
}
const params = {
Bucket: bucket,
Key: key,
};
try {
const stream = await s3.getObject(params).createReadStream();
return await csv().fromStream(stream);
} catch (err) {
console.log(err);
const message = `Error getting object ${key} from bucket ${bucket}. Make sure they exist and your bucket is in the same region as this function.`;
console.log(message);
throw new Error(message);
}
}; Zip the contents of your project. You'll notice in the top right the Function URL. Copy that. We'll use this in Budibase later. Make sure the runtime settings are correct! So in this case it should be Step 3 - Add the REST Query and TableCreate a new REST Query with the following params. You can put in your own bucket and key. Note the schema will need to be static for this to work. E.g. the users must be uploading CSVs that share column names, but the row contents can obviously be different. Add a Data Provider for the REST Query source with a table underneath. Result |
Beta Was this translation helpful? Give feedback.
-
Obrigado pela resposta! |
Beta Was this translation helpful? Give feedback.
-
Is it possible to create a screen to upload an excel or CSV file and later read its data? In short, I need to create a screen so that the user can import an Excel/CSV spreadsheet and read its data.
Beta Was this translation helpful? Give feedback.
All reactions