Javascript 如何在admin bro中配置bucket以本地存储上传的文件

Javascript 如何在admin bro中配置bucket以本地存储上传的文件,javascript,node.js,express,Javascript,Node.js,Express,我正在使用express和admin-bro及其插件@admin-bro/upload将上传的图像文件存储在服务器中 AdminBro对象使用以下AdminBroOptions const adminBro=new adminBro({ 资源:[ { 资源:家具, 选项:{ 特性:{ “\u id”:{ isVisible:{list:false,filter:true,show:true,edit:false} }, 图片:{ isVisible:false } } }, 功能:[上传功能](

我正在使用
express
admin-bro
及其插件
@admin-bro/upload
将上传的图像文件存储在服务器中

AdminBro
对象使用以下
AdminBroOptions

const adminBro=new adminBro({
资源:[
{
资源:家具,
选项:{
特性:{
“\u id”:{
isVisible:{list:false,filter:true,show:true,edit:false}
},
图片:{
isVisible:false
}
}
},
功能:[上传功能]({
提供者:{local:{bucket:path.join(uu dirname,'public','images','furniture')},
特性:{
键:“image.path”,
bucket:'image.folder',
mimeType:'image.type',
大小:“image.size”,
文件名:“image.filename”,
文件:“上传文件”
}
})]
}
],
品牌:{
公司名称:“弗兰的家具”
}
})
文件夹结构:

我遵循本教程主要是为了
admin-bro
配置:

我还在server.js文件中添加了
app.use('/public',express.static('public'))

但我在上载图像文件时遇到此错误:

(node:153012) ExperimentalWarning: The fs.promises API is experimental
Error: EPERM: operation not permitted, mkdir 'F:'
如果我将bucket属性更改为“public”:

provider:{local:{bucket:'public'}
弹出以下错误(注意“public”文件夹位于项目文件夹的F:/not F:/path中:

(node:163580) ExperimentalWarning: The fs.promises API is experimental
Error: EXDEV: cross-device link not permitted, rename 'C:\Users\Lenovo\AppData\Local\Temp\upload_4ca3c78a0517022a555815196102aee6' -> 'F:\public\5f98496b31e9d37efe9a2584\1.jpg'
家具模型(如果需要):

const Image=newmongoose.Schema({
路径:字符串,
类型:字符串,
尺寸:数量,
文件夹:String,
文件名:字符串
})
const FurnitureSchema=新的mongoose.Schema({
姓名:{
类型:字符串,
必填项:true
},
说明:{
类型:字符串,
必填项:true
},
价格:{
类型:数字,
必填项:true
},
地位:{
类型:字符串,
枚举:[“显示”、“隐藏”],
默认值:“显示”,
必填项:true
},
条件:{
类型:字符串,
枚举:['new','used'],
必填项:true
},
图像:图像,
类别:{
类型:mongoose.Schema.Types.ObjectId,
要求:正确,
参考:“类别”
}
})
所以在我看来,这个问题主要是因为桶选项的配置不正确。任何帮助都将不胜感激


项目路径(如果需要):F:\Tutorials\Self Projects\frans node

我通过自己编写一个自定义基本提供程序并手动复制+删除文件来解决此问题:

从'@admin bro/upload'导入{BaseProvider}
从“admin bro”导入{ActionContext,UploadedFile}
从“fs”导入{promises,existsSync}
从“路径”导入{resolve,dirname}
导出类UploadProvider扩展BaseProvider{
资产路径:字符串
构造函数(bucket:string,assetPath:string){
//它需要bucket作为参数来正确地将其传递给其他方法
超级(桶)
this.assetPath=assetPath
}
异步上传(文件:UploadedFile,键:string,上下文:ActionContext):承诺{
const fullPath=resolve(this.assetPath,key)
常量dirPath=dirname(完整路径)
如果(!existsSync(dirPath)){
mkdir(dirPath,{recursive:true})
}
wait promises.copyFile(file.path,fullPath)
等待承诺。取消链接(file.path)
返回键
}
异步删除(key:string,bucket:string,context:ActionContext):承诺{
const filePath=resolve(this.assetPath,key)
if(existsSync(文件路径)){
等待承诺。取消链接(文件路径)
常量dirPath=dirname(文件路径)
const otherFiles=wait promises.readdir(dirPath)
if(otherFiles&&otherFiles.length==0){
等待承诺.rmdir(dirPath)
}
}
}
路径(key:string,bucket:string,context:ActionContext):Promise | string{
返回“/”+桶
}
}
然后,像这样使用它:

/。。。
const provider=new UploadProvider(“资产”,资产路径)
// ...
特点:[
uploadFileFeature({provider,…})
]