firebase-storage
v1.1.4
Published
Easily operate Google cloud storage with a private key
Downloads
447
Readme
firebase-storage
Easily operate Google cloud storage with a private key.
Works with Edge runtime
.
Sample
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);