uplo
v0.21.0
处理文件上传到各种存储服务,如 Amazon S3、Google Cloud 等。它还支持各种类型的 ORM 适配器,如 Prisma。
将@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 许可证条款作为开源提供。