Coder Social home page Coder Social logo

Comments (5)

Benjamin-Urzua avatar Benjamin-Urzua commented on July 20, 2024

For now im avoiding this sending the no data file to a trash directory, but obviously its not the best solution, it looks like this

  module.exports.crearProductos = (req, res) => {
  const form = new formidable.IncomingForm()
  const imgFolder = path.join(__dirname, "../public/img", "producto")

  var productos = []

  form.on('fileBegin', (formName, file) => {

      
      let numArchivo = formName.slice(-1)
      let nuevoArchivo = file
      let nombreArchivo = 'img_prod_0' + numArchivo

      if (file.mimetype == 'application/octet-stream') {
          nuevoArchivo.filepath = imgFolder + '/basura/' + nombreArchivo + '.png'
      }else{
          nuevoArchivo.filepath = imgFolder + '/' + nombreArchivo + '.png'
      }
      
      nuevoArchivo.newFilename = nombreArchivo
      form.emit('data', { name: 'fileBegin', value: nuevoArchivo });
  });

(My code is in spanish)

from formidable.

GrosSacASac avatar GrosSacASac commented on July 20, 2024

So you want to update something about a file, ? I suggest to handle that on a different URL but I am not sure I understand the question

from formidable.

Benjamin-Urzua avatar Benjamin-Urzua commented on July 20, 2024

So you want to update something about a file, ? I suggest to handle that on a different URL but I am not sure I understand the question

Uhm yeah, use another URL its probably the best way to do this, but my site is designed to create and update on the same place.

I'm using a plugin called Kartik Input File for this. The way this plugin works is that it allows for a more aesthetic way of uploading files. However, the problem I'm having is that even if the user decides not to upload anything, the plugin will still submit a file without any information in it. Additionally, the files will always have the same name for better data management. Specifically, the application focuses on creating products, which consist of a name, a link, a description, and a photo. Each of these fields has a similar naming convention such as txt_product_01 or img_product_02. If the product is product_01, the image will be called img_product_01. So every time the user updates this product, Formidable replaces the existing file. However, I only want this to happen when the user has actually uploaded a file. Otherwise, I would like to get rid of the file that comes without any data. But if I try to do this using the methods provided by Formidable, it will also get rid of the other fields that are accompanied by the file. For example, if the product is product_01 and its image comes without data, when trying to get rid of img_product_01, all the other fields, such as txt_productName_01, txt_linkProduct_01, and txt_descriptionProduct_01, will also be discarded. And this only happens when updating the product because the user may not always want to update the photo but may just want to update the product name.

from formidable.

GrosSacASac avatar GrosSacASac commented on July 20, 2024

I will think about it

from formidable.

GrosSacASac avatar GrosSacASac commented on July 20, 2024

Use option
allowEmptyFiles: false,

then check for the specific error
if (err) {
if (err.code ===formidableErrors.noEmptyFiles) {
update an item

from formidable.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.