Sube sin autenticación mediante la creación de una carga reanudable y pasa esa ubicación a file.save

Ejemplo en Node.js: https://github.com/googleapis/nodejs-storage/pull/1711

Muestra de código

Node.js

Si deseas obtener más información, consulta la documentación de referencia de la API de Cloud Storage para Node.js.

/**
 * TODO(developer): Uncomment the following lines before running the sample.
 */
// The ID of your GCS bucket
// const bucketName = 'your-unique-bucket-name';

// The contents that you want to upload
// const contents = 'these are my contents';

// The new ID for your GCS file
// const destFileName = 'your-new-file-name';

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

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

async function uploadWithoutAuthenticationCreateResumableUploadStrategy() {
  const file = storage.bucket(bucketName).file(destFileName);

  // Returns an authenticated endpoint to which
  // you can make requests without credentials.
  const [location] = await file.createResumableUpload(); //auth required

  // Passes the location to file.save so you don't need to
  // authenticate this call
  await file.save(contents, {
    uri: location,
    resumable: true,
    validation: false,
  });

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

uploadWithoutAuthenticationCreateResumableUploadStrategy().catch(
  console.error
);

¿Qué sigue?

Para buscar y filtrar muestras de código para otros productos de Google Cloud, consulta el navegador de muestra de Google Cloud.