adminjs-upload
adminjs-upload copied to clipboard
Error: You cannot upload file for not persisted record. Save record first
My Setup
Schema -
export const UploadedFile = new mongoose.Schema({
path: String,
type: String,
size: Number,
folder: String,
filename: String,
});
export const Pods = mongoose.model('Pods', {
name: {
type: String,
required: true,
},
message: {
type: String,
required: true,
defualt: '',
},
uploadedFile: UploadedFile,
});
config --
{
resource: Pods,
options: {
parent: 'Manage Groups',
properties: {},
},
features: [
uploadFeature({
provider: { local: { bucket: 'uploads' } },
properties: {
key: 'uploadedFile.path',
bucket: 'uploadedFile.folder',
mimeType: 'uploadedFile.mime',
size: 'uploadedFile.size',
filename: 'uploadedFile.filename',
file: 'uploadFile',
},
}),
],
Express -
app.use('/uploads', express.static('uploads'));
I get this error on trying to upload an image on a record. Looking at the code it seems that this is result of a record without an id. But my record has an id to confirm i created a new record without uploading an image and then tried to upload with the same result.
Everything else works fine its only the image upload thats not working. Would appreciate any help. Thanks.
@SimonB407 This is the error the OP is facing. I am facing the same issue
My Setup
Schema -
export const UploadedFile = new mongoose.Schema({ path: String, type: String, size: Number, folder: String, filename: String, }); export const Pods = mongoose.model('Pods', { name: { type: String, required: true, }, message: { type: String, required: true, defualt: '', }, uploadedFile: UploadedFile, });config --
{ resource: Pods, options: { parent: 'Manage Groups', properties: {}, }, features: [ uploadFeature({ provider: { local: { bucket: 'uploads' } }, properties: { key: 'uploadedFile.path', bucket: 'uploadedFile.folder', mimeType: 'uploadedFile.mime', size: 'uploadedFile.size', filename: 'uploadedFile.filename', file: 'uploadFile', }, }), ],Express -
app.use('/uploads', express.static('uploads'));I get this error on trying to upload an image on a record. Looking at the code it seems that this is result of a record without an id. But my record has an id to confirm i created a new record without uploading an image and then tried to upload with the same result.
Everything else works fine its only the image upload thats not working. Would appreciate any help. Thanks.
brother same issue