本文整理匯總了TypeScript中aws-sdk.S3.putObject方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript S3.putObject方法的具體用法?TypeScript S3.putObject怎麽用?TypeScript S3.putObject使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類aws-sdk.S3
的用法示例。
在下文中一共展示了S3.putObject方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: returnScreenshot
// Returns the S3 url or local file path
async returnScreenshot(): Promise<string> {
const data = await screenshot(this.client)
// check if S3 configured
if (process.env['CHROMELESS_S3_BUCKET_NAME'] && process.env['CHROMELESS_S3_BUCKET_URL']) {
const s3Path = `${cuid()}.png`
const s3 = new AWS.S3()
await s3.putObject({
Bucket: process.env['CHROMELESS_S3_BUCKET_NAME'],
Key: s3Path,
ContentType: 'image/png',
ACL: 'public-read',
Body: new Buffer(data, 'base64'),
}).promise()
return `https://${process.env['CHROMELESS_S3_BUCKET_URL']}/${s3Path}`
}
// write to `/tmp` instead
else {
const filePath = `/tmp/${cuid()}.png`
fs.writeFileSync(filePath, Buffer.from(data, 'base64'))
return filePath
}
}
示例2: returnPdf
// Returns the S3 url or local file path
async returnPdf(options?: PdfOptions): Promise<string> {
const data = await pdf(this.client, options)
// check if S3 configured
if (
process.env['CHROMELESS_S3_BUCKET_NAME'] &&
process.env['CHROMELESS_S3_BUCKET_URL']
) {
const s3Path = `${cuid()}.pdf`
const s3 = new AWS.S3()
await s3
.putObject({
Bucket: process.env['CHROMELESS_S3_BUCKET_NAME'],
Key: s3Path,
ContentType: 'application/pdf',
ACL: 'public-read',
Body: new Buffer(data, 'base64'),
})
.promise()
return `https://${process.env['CHROMELESS_S3_BUCKET_URL']}/${s3Path}`
} else {
// write to `${os.tmpdir()}` instead
const filePath = path.join(os.tmpdir(), `${cuid()}.pdf`)
fs.writeFileSync(filePath, Buffer.from(data, 'base64'))
return filePath
}
}
示例3: deploy
async deploy(args) {
this._s3 = new (this._getAWS(this.resources)).S3();
let bucket = this.resources.target;
let source = path.resolve(this.resources.source);
this.bucket = bucket;
this.source = source;
console.log("Deploy", source, "on S3 Bucket", bucket);
await this.createBucket(bucket);
let files = Finder.from(source).findFiles();
// Should implement multithread here - cleaning too
for (let i in files) {
let file = files[i];
let key = path.relative(source, file);
// Need to have mimetype to serve the content correctly
let mimetype = mime.contentType(path.extname(file));
await this._s3
.putObject({
Bucket: bucket,
Body: fs.createReadStream(file),
Key: key,
ContentType: mimetype
})
.promise();
console.log("Uploaded", file, "to", key, "(" + mimetype + ")");
}
if (!this.resources.staticWebsite) {
return;
}
await this._createWebsite();
}
示例4: Promise
return new Promise((ok, fail) => {
s3.putObject(args, (err, data) => {
if (err) {
return fail(err);
}
ok();
});
});
示例5: reject
return new Promise<string>((resolve, reject) => {
s3.putObject(params, (err, data) => {
if (err) {
reject(`S3 Error: ${err.message}`)
} else {
resolve(`https://${domain}/${params.Bucket}/${key}`)
}
})
})
示例6:
.then(() => {
return this._s3
.putObject({
Bucket: bucket,
Body: fs.createReadStream(info.src),
Key: info.key,
ContentType: mimetype
})
.promise();
})
示例7: uploadToS3
export async function uploadToS3(data: string, contentType: string): Promise<string> {
const s3ContentType = s3ContentTypes[contentType]
if (!s3ContentType) {
throw new Error(`Unknown S3 Content type ${contentType}`)
}
const s3Path = `${getS3ObjectKeyPrefix()}${cuid()}.${s3ContentType.extension}`
const s3 = new AWS.S3()
await s3
.putObject({
Bucket: getS3BucketName(),
Key: s3Path,
ContentType: contentType,
ACL: 'public-read',
Body: Buffer.from(data, 'base64'),
})
.promise()
return `https://${getS3BucketUrl()}/${s3Path}`
}