Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const {Storage} = require('@google-cloud/storage');
- const ObjectToCsv = require('objects-to-csv');
- const uploadFile = async ({file, destination, bucket}) => {
- return new Promise((resolve, reject) => {
- const storage = new Storage();
- storage.bucket(bucket).upload(file, {
- destination: destination
- })
- .then(() => {
- return resolve({
- "code": 200,
- "message": `success upload file ${file} to bucket ${bucket}`
- });
- })
- .catch((error) => {
- return reject({
- "code": 400,
- "error": error.message
- })
- });
- })
- }
- const writeCsv = async ({filename, payload}) => {
- return new Promise(async (resolve, reject) => {
- try {
- payload.map((data) => data.UPDATED_DATE = new Date(data.UPDATED_DATE).toISOString());
- const csvFile = new ObjectToCsv(payload);
- await csvFile.toDisk(`./uploads/geotagging/${filename}`);
- return resolve(`./uploads/geotagging/${filename}`);
- } catch (error) {
- return reject({
- "code": 400,
- "error": error
- });
- }
- });
- }
- module.exports = {
- uploadFile,
- writeCsv
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement