本文整理汇总了TypeScript中aws-sdk.S3.getObject方法的典型用法代码示例。如果您正苦于以下问题:TypeScript S3.getObject方法的具体用法?TypeScript S3.getObject怎么用?TypeScript S3.getObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类aws-sdk.S3
的用法示例。
在下文中一共展示了S3.getObject方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: Promise
return new Promise((resolve, reject) => {
s3.getObject({ Bucket, Key })
.on("httpDone", x => {
resolve(JSON.parse(x.httpResponse.body.toString()));
})
.send();
});
示例2: runS3Script
runS3Script(cb: {(err: Error | null, res: any)}) {
this.s3.getObject({Bucket: this.bucket!, Key: this.scriptUrl!}, (err, resp) => {
if (err) return cb(err, null)
const script = resp.Body.toString('utf8')
this.runScript(script, cb)
})
}
示例3: Promise
return new Promise((resolve, reject) => {
const s3 = new AWS.S3({
accessKeyId, secretAccessKey,
region: region || 'ap-northeast-1',
apiVersion: '2006-03-01'
});
return s3.getObject({ Bucket: bucket, Key: key }, (error, data) => {
if (error) {
reject(error);
} else {
resolve(JSON.parse(data.Body));
}
});
});
示例4: Promise
return new Promise((ok, fail) => {
let args = {
Bucket: this.config.bucket,
Key: this.encodeKey(key)
};
this.s3.getObject(args, (err, data) => {
if (err) {
if (err.code === 'NoSuchKey' || err.code === 'AccessDenied') {
return ok(null);
}
return fail(err);
}
let raw = data.Body.toString();
ok(new FileContents(key, data.LastModified, data.ContentType, raw));
});
});
示例5: 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 {
//.........这里部分代码省略.........