uplo
v0.21.0
處理文件上傳到各種儲存服務,如 Amazon S3、Google Cloud 等。
將@uplo/node
加入到 package.json
yarn add @uplo/node
安裝適配器(例如 Prisma)
yarn add @uplo/adapter-prisma dataloader
安裝服務(例如 S3)
yarn add @uplo/service-s3
定義uplo實例
import Uplo from '@uplo/node' ;
import PrismaAdapter from '@uplo/adapter-prisma' ;
import GCSService from '@uplo/service-gcs' ;
const config = {
privateKey : process . env . APPLICATION_SECRET , // Used to sign direct upload keys
signedIdExpiresIn : 60 * 60 , // Time how long a Signed ID is valid
} ;
const uplo = Uplo ( {
config ,
adapter : new PrismaAdapter ( { prisma } ) ,
services : {
s3 : S3Service ( {
isPublic : false ,
region : process . env . AWS_REGION ,
bucket : process . env . AWS_BUCKET ,
accessKeyId : '*****' ,
secretAccessKey : '*****' ,
} ) ,
} ,
attachments : {
user : {
avatar : true , // pass true to use default options
} ,
post : {
images : { multiple : true }
}
} ,
} ) ;
const attachment = await uplo . attachments . user ( 123 ) . avatar . attachFile ( await blobFileInput ( {
path : '/home/images/image.png'
} ) )
該軟體包根據 MIT 許可證條款作為開源提供。