本文整理汇总了TypeScript中aws-sdk.S3.headObject方法的典型用法代码示例。如果您正苦于以下问题:TypeScript S3.headObject方法的具体用法?TypeScript S3.headObject怎么用?TypeScript S3.headObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类aws-sdk.S3
的用法示例。
在下文中一共展示了S3.headObject方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: getConfig
clips.map(async ({ id, path, sentence }) => {
// We get a 400 from the signed URL without this request
await this.s3
.headObject({
Bucket: getConfig().BUCKET_NAME,
Key: path,
})
.promise();
return {
id,
glob: path.replace('.mp3', ''),
text: sentence,
sound: this.getPublicUrl(path),
};
})
示例2: callbackRuntime
export default callbackRuntime(async (event: APIGatewayEvent) => {
// NOTE currently needed for backward compatibility
if (event.path.split('/')[1] !== 'v1') {
try {
// log projectId of projects using the old API version
const client = new GraphQLClient(process.env['GRAPHCOOL_ENDPOINT']!, {
headers: {
Authorization: `Bearer ${process.env['GRAPHCOOL_PAT']}`,
},
})
await client.request(`mutation {
createApiUser(projectId: "${event.path.split('/')[1]}") { id }
}`)
} catch (e) {
if (e.response.errors[0].code !== 3010) {
throw e
}
}
return {
statusCode: 301,
body: '',
headers: {
Location: `https://images.graph.cool/v1${event.path}`,
},
}
}
const [paramsErr, params] = parseParams(event.path)
if (paramsErr) {
return {
statusCode: 400,
body: paramsErr.toString(),
}
}
const { projectId, fileSecret, crop, resize } = params!
const options = {
Bucket: process.env['BUCKET_NAME']!,
Key: `${projectId}/${fileSecret}`,
}
const {
ContentLength,
ContentType,
ContentDisposition,
} = await s3.headObject(options).promise()
if (ContentLength! > 25 * 1024 * 1024) {
return {
statusCode: 400,
body: 'File too big',
}
}
if (!ContentType!.includes('image')) {
return {
statusCode: 400,
body: 'File not an image',
}
}
// return original for gifs, svgs or no params
if (
ContentType === 'image/gif' ||
ContentType === 'image/svg+xml' ||
(resize === undefined && crop === undefined)
) {
const obj = await s3.getObject(options).promise()
const body = (obj.Body as Buffer).toString('base64')
return base64Response(body, ContentType!, ContentDisposition!)
}
const s3Resp = await s3.getObject(options).promise()
const stream = sharp(s3Resp.Body)
try {
const config = getConfig({ resize, crop })
stream.limitInputPixels(false)
if (config.crop) {
stream.extract({
left: config.crop.x,
top: config.crop.y,
width: config.crop.width,
height: config.crop.height,
})
}
if (config.resize) {
stream.rotate()
stream.resize(config.resize.width, config.resize.height)
if (config.resize.force) {
stream.ignoreAspectRatio()
} else {
//.........这里部分代码省略.........