vendredi 2 avril 2021

Upload Image in Nuxt and Express

So, I have a Nuxt form filled with input and a file upload in it. The data structure look like this:

  data() {
    return {
      product_name: '',
      product_image: ''
    }
  }

In the backend, I have products table and file_uploads table. file_uploads table contain file_name and product_id (FK to products table). I have a few questions here:

  1. Should I append all the product data from Nuxt into a formData object in JS and the uploading file thing will be handled directly in the backend without calling separate API to upload file?
  2. Or should I create a new product first, return the ID of the product, and then call separate API to upload file with product_id from the return data?

Thank you in advance

Aucun commentaire:

Enregistrer un commentaire