编程语言/S3:修订间差异
来自康健生活
| 第424行: | 第424行: | ||
}).promise(); | }).promise(); | ||
} catch (error) {}</syntaxhighlight> | } catch (error) {}</syntaxhighlight> | ||
读取的时候使用流。 | |||
<syntaxhighlight lang="javascript"> | |||
module.exports = class extends BaseRest { | |||
async getAction() { | |||
const file = await storeInstance.get(s3Key).catch(err => err); | |||
const pipe = s3.getObject({Bucket: bucket, Key: name}).createReadStream(); | |||
pipe.on('error', err => { | |||
err.status = err.statusCode; | |||
throw err; | |||
}); | |||
this.ctx.type = this.id.match(/\.(\w+)$/)[1]; | |||
this.ctx.body = pipe; | |||
} | |||
};</syntaxhighlight> | |||
== error == | == error == | ||