本文整理匯總了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');
}