mirror of
https://github.com/laosb/ghos3.git
synced 2025-05-01 08:01:08 +00:00
file is streamed rather than buffered to reduce memory usage.
This commit is contained in:
parent
004503034e
commit
a5cb4d3b8f
1 changed files with 3 additions and 5 deletions
|
@ -6,7 +6,7 @@ import {
|
||||||
} from '@aws-sdk/client-s3'
|
} from '@aws-sdk/client-s3'
|
||||||
import StorageBase, { type ReadOptions, type Image } from 'ghost-storage-base'
|
import StorageBase, { type ReadOptions, type Image } from 'ghost-storage-base'
|
||||||
import { join } from 'path'
|
import { join } from 'path'
|
||||||
import { readFile } from 'fs/promises'
|
import { createReadStream } from 'fs'
|
||||||
import type { Readable } from 'stream'
|
import type { Readable } from 'stream'
|
||||||
import type { Handler } from 'express'
|
import type { Handler } from 'express'
|
||||||
|
|
||||||
|
@ -152,10 +152,8 @@ class S3Storage extends StorageBase {
|
||||||
async save(image: Image, targetDir?: string) {
|
async save(image: Image, targetDir?: string) {
|
||||||
const directory = targetDir || this.getTargetDir(this.pathPrefix)
|
const directory = targetDir || this.getTargetDir(this.pathPrefix)
|
||||||
|
|
||||||
const [fileName, file] = await Promise.all([
|
const fileName = await this.getUniqueFileName(image, directory);
|
||||||
this.getUniqueFileName(image, directory),
|
const file = createReadStream(image.path)
|
||||||
readFile(image.path),
|
|
||||||
])
|
|
||||||
|
|
||||||
let config: PutObjectCommandInput = {
|
let config: PutObjectCommandInput = {
|
||||||
ACL: this.acl,
|
ACL: this.acl,
|
||||||
|
|
Loading…
Add table
Reference in a new issue