本文整理汇总了TypeScript中@google-cloud/storage.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了default函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: storeImage
public storeImage(buffer: Buffer): Promise<string> {
const blobStream = new ReadableStreamBuffer()
blobStream.put(buffer)
blobStream.stop()
const storage = gcs({
credentials: process.env.GOOGLE_CLOUD_CREDENTIALS_JSON ? JSON.parse(process.env.GOOGLE_CLOUD_CREDENTIALS_JSON) : undefined,
projectId: process.env.GOOGLE_CLOUD_PROJECT,
})
const bucketName = process.env.GOOGLE_CLOUD_BUCKET
const bucket = storage.bucket(bucketName)
const key = this.randomPath()
const file = bucket.file(key)
return new Promise<string>((resolve, reject) => {
blobStream
.pipe(file.createWriteStream({public: true}))
.on("error", (err: any) => {
reject(`Google Cloud Storage Error: ${JSON.stringify(err)}`)
}).on("finish", () => {
resolve(`https://storage.googleapis.com/${bucketName}/${key}`)
})
})
}
示例2: openScreenshotsBucket
export function openScreenshotsBucket() {
let gcs = cloudStorage({
projectId: 'material2-screenshots',
credentials: {
client_email: 'firebase-adminsdk-t4209@material2-screenshots.iam.gserviceaccount.com',
private_key: decode(process.env['MATERIAL2_SCREENSHOT_FIREBASE_KEY'])
},
});
// Reference the existing appspot bucket.
return gcs.bucket('material2-screenshots.appspot.com');
}