0

I need to upload and share my documents using Google Cloud and nodeJS but I'm not sure how to do it exactly.

1
  • The best way consists in using @google-cloud/storage NPM library. This allows to upload or download files (among other operations). There are good code samples in the official documentation. Commented Nov 28, 2019 at 13:41

2 Answers 2

1

The best way is to check the documentation and to find out more about Google Cloud Storage and how to upload your files or documents to Google Cloud Storage.

Regarding uploading a CSV file to Google Cloud Storage, you can access this link where you can use different ways to upload files to Google Cloud Storage.

For your case use, here is the code sample to upload a file using nodeJS. Here in your case just change in the const field for the filename to the path of your file and instead of .txt you should specify .csv.

/**
 * TODO(developer): Uncomment the following lines before running the sample.
 */
// const bucketName = 'Name of a bucket, e.g. my-bucket';
// const filename = 'Local file to upload, e.g. ./local/path/to/file.txt';

// Imports the Google Cloud client library
const {Storage} = require('@google-cloud/storage');

// Creates a client
const storage = new Storage();

async function uploadFile() {
  // Uploads a local file to the bucket
  await storage.bucket(bucketName).upload(filename, {
    // Support for HTTP requests made with `Accept-Encoding: gzip`
    gzip: true,
    // By setting the option `destination`, you can change the name of the
    // object you are uploading to a bucket.
    metadata: {
      // Enable long-lived HTTP caching headers
      // Use only if the contents of the file will never change
      // (If the contents will change, use cacheControl: 'no-cache')
      cacheControl: 'public, max-age=31536000',
    },
  });

  console.log(`${filename} uploaded to ${bucketName}.`);
}

uploadFile();
Sign up to request clarification or add additional context in comments.

Comments

0

Check out this GitHub repository its has examples for cloud storage with Nodejs

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.