Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/node-libraries/firebase-storage

Easily operate Google cloud storage with a private key
https://github.com/node-libraries/firebase-storage

Last synced: about 2 months ago
JSON representation

Easily operate Google cloud storage with a private key

Awesome Lists containing this project

README

        

# firebase-storage

Easily operate Google cloud storage with a private key.
Works with `Edge runtime`.

## Sample

```ts
import { getStorage } from "firebase-storage";

const privateKey =
"-----BEGIN PRIVATE KEY-----\nXXXXXXXXXXXXXXXX-----END PRIVATE KEY-----\n";
const clientEmail =
"[email protected]";
const bucket = "XXXXXXXX.appspot.com"; // Can also be specified in each function
const parallels = 5; //default 1000

async function main() {
const storage = getStorage({ privateKey, clientEmail, bucket, parallels });
const file = new Blob(["Test value"], {
type: "text/plain",
});

await storage
.upload({
published: true,
name: "test",
file,
metadata: {
cacheControl: "public, max-age=31536000, immutable",
},
})
.then(console.log);
await storage.list({ bucket }).then((objects) => objects.map(console.log));
await storage.info({ name: "test" }).then(console.log);
await storage
.download({
name: "test",
})
.then((v) => {
console.log(new TextDecoder().decode(v));
});
await storage.del({ name: "test" }).then(console.log);
await storage.infoBucket({ bucket }).then(console.log);
await storage.updateBucket({ bucket, body: {} }).then(console.log);
}

main().catch(console.error);
```