Y
Y
yurecitpear2022-04-11 20:37:22
Node.js
yurecitpear, 2022-04-11 20:37:22

What's wrong with mongoose?

Several images are not loaded (one is normally loaded and saved) multer library

async create ({commit}, {title, text, price, category, categoryname, image, images}) {
    
    try {
      let imageFiles = []
      for (let i = 0; i < images.length; i++) {
        imageFiles.push(images[i].raw)
      }

      const fd = new FormData()
      fd.append('title', title)
      fd.append('text', text)
      fd.append('price', price)
      fd.append('category', category)
      fd.append('categoryname', categoryname)
      fd.append('image', image)
      fd.append('images', imageFiles)

      console.log(imageFiles)
      // for(let i = 0; i < images.length; i++) {
      //   fd.append("images", images[i]);
      // }
      for (var pair of fd.entries()) {
        console.log(pair[0]+ ', ' + pair[1]); 
      }
      return await this.$axios.$post('/api/post/admin', fd)

    } catch (e) {
      commit('setError', e, {root: true})
      throw e
    }
  },

// код роутера
router.post(
  '/admin/',
  passport.authenticate('jwt', {session: false}),
  upload.single('image'), 
  upload.array('images'), 
  ctr.create 
)

throws an error on the mongoose schema, although if you remove upload.array('images') then everything works fine (but a few images are not loaded)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question