Comments (5)
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.
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.
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.
I will think about it
from formidable.
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)
- Do we have plan to rewrite logic in typescript for more clear structure? HOT 1
- Encrypting a stream received via Formidable.js before streaming to S3 fails HOT 2
- Formidable V2 Filter issue HOT 2
- is v3 ESM only? HOT 8
- null values are parsed into 'null' string HOT 2
- Migration guide from v2 to v3? HOT 4
- What are the breaking changes in v3.0.0? HOT 4
- formidable is stuck at parse function's callback HOT 9
- Formdata is string, but parse resulting is array? HOT 3
- TS Options Type Definition missing createDirsFromUploads HOT 1
- Attach fields to req.body and files to req.files like multer HOT 1
- [deps] Check for breaking changes in Dependabot PRs HOT 1
- @cunha-ambisis you should create a new form on each request (inside app.use) HOT 1
- Since V3 I get "formidable is not a function" - using require not import HOT 12
- Make multipart parser less dependent on NodeJS HOT 2
- Regression in Formidable v3, which can crash a server HOT 7
- form.parse's Promise never resolves in tests HOT 8
- Hexoid Error (?)
- Buffer usage HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from formidable.