你的文本我尝试使用具有架构的 AdminJS 在 mongoDB 上上传图像
-------------------- ifile.mjs --------------------------
import { mongoose } from 'mongoose';
export const ImageSchema = new mongoose.Schema({
mime: {type: String, required: true},
});
const Image = mongoose.model("Image", ImageSchema);
export default Image;
------------------startup.mjs --------------------------
import { mongoose } from 'mongoose';
const startupSchema = new mongoose.Schema(
{
Logo: { type: Buffer },
StartUp_Name: { type: String, required: true },
Idea_Description:{ type: String, },
},
{
timestamps: {createdAt: 'created_at', updatedAt: 'updated_at'}
}
);
const StartUp = mongoose.model("StartUp", startupSchema);
export default StartUp;
我想在徽标的启动架构中上传图像,但这不起作用
-------------- app.mjs----------
// All required dependencies
import uploadFeature from '@adminjs/upload';
import StartUp from './collection/startup.mjs'
import Image, { ImageSchema } from './collection/ifile.mjs'
dotnev.config("./.env")
const PORT = process.env.PORT || 3002
const start = async () =\> {
const MongoStore = MongoDBStore(session);
connectDB()
const HomePage = { name: 'Home Page', icon: 'Home'}\`
const admin = new AdminJS({
resources: [
{
resource: StartUp,
options:
{
navigation: HomePage,
bio: {
isVisible: {
edit: true,
show: true,
list: true,
filter: true,
},
},
properties: {
// mime: { type: 'string',},
// image: { isVisible: true, }
},
actions: {
uploadFile: {
provider: { aws: S3 },
validation: { mimeTypes: \['image/png', 'application/pdf'\] },
properties: { key: S3.accessKeyId, },
},
// features:[
// uploadFeature({
// provider: { aws: S3 },
// validation: { mimeTypes: ['image/png', 'image/jpg', 'image/jpeg'] },
// properties: {
// key: process.env.AWS_ACCESS_KEY_SECRET
// mimeType: 'mimeTypes',
// },
// }),
// ]
},
editProperties: ['StartUp_Name', 'Idea_Description'],
filterProperties: ['StartUp_Name', 'Idea_Description', 'created_at'],
showProperties: ['StartUp_Name', 'Idea_Description'],
},
],
rootPath: "/admin",
},
})
const adminRouter = AdminJSExpress.buildRouter(admin)
app.use(cors());
app.use(admin.options.rootPath, adminRouter)
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.listen(PORT, () => {
console.log(`AdminJS started on http://localhost:${PORT}${admin.options.rootPath}`)
})
start()
如果我使用uploadFile代码,那么在右上角,有一个上传按钮,但它不起作用。
如果我使用uploadFeature(注释代码),则会出现错误...
............./backend/node_modules/@adminjs/upload/build/features/upload-file/utils/bundle-component.js:7
return loader.add(componentName, componentPath);
^
TypeError: Cannot read properties of undefined (reading 'add')
at bundleComponent (............./backend/node_modules/@adminjs/upload/build/features/upload-file/utils/bundle-component.js:7:19)
at uploadFeature (............./backend/node_modules/@adminjs/upload/build/features/upload-file/upload-file.feature.js:63:31)
at uploadFileFeature (............./backend/node_modules/@adminjs/upload/build/features/upload-file/upload-file.feature.js:102:12)
at start (............./backend/app.mjs:184:17)
at ............./backend/app.mjs:446:1
Node.js v18.16.0
\[nodemon\] app crashed - waiting for file changes before starting...
我也尝试使用本地文件系统,但也遇到了同样的错误。
features: [
uploadFeature({
provider: localProvider,
validation: { mimeTypes: ['image/png', 'application/pdf'],},
options: {
key: 323,
bucket: './public/files',
s3Key: 'uploadFeature',
},
}),
],
我使用https://docs.adminjs.co/basics/features/upload作为参考。
我只是希望在单击上传时,我能够使用弹出窗口浏览图像
Yash,我也遇到了同样的问题,你能帮我找到你找到的解决方案吗?
谢谢!