adminjs-upload icon indicating copy to clipboard operation
adminjs-upload copied to clipboard

Error: You cannot upload file for not persisted record. Save record first

Open PranaytheSingh opened this issue 4 years ago • 2 comments

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.

PranaytheSingh avatar Jan 23 '21 07:01 PranaytheSingh

image @SimonB407 This is the error the OP is facing. I am facing the same issue

yash-ultrahuman avatar Feb 15 '21 11:02 yash-ultrahuman

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

kanojia-gaurav avatar May 05 '21 10:05 kanojia-gaurav