Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting Fields out of json #811

Closed
gaurishhs opened this issue Jan 7, 2022 · 4 comments
Closed

Getting Fields out of json #811

gaurishhs opened this issue Jan 7, 2022 · 4 comments

Comments

@gaurishhs
Copy link

gaurishhs commented Jan 7, 2022

Support plan

  • Which support plan is this issue covered by? (Community, Sponsor, Enterprise): Community
  • Currently blocking your project/work? (yes/no): yes
  • Affecting a production system? (yes/no): yes

Context

  • Node.js version: 16.x.x
  • Release Line of Formidable (Legacy, Current, Next): Current
  • Formidable exact version: v2
  • Environment (node, browser, native, OS): MacOS
  • Used with (popular names of modules): Express

What are you trying to achieve or the steps to reproduce?

  • I get a very badly formatted json when i try logging files, I want to access the path of the file, But it's getting impossible i tried console.log(files.'') which wont actually work tried console.log(files[0]) but that too didnt work.
app.post('/upload', async (req, res) => {
    const form = new formidable.IncomingForm()
    form.parse(req, (error: any, fields: any, files: any) => {
        if(error) throw new Error(error)
        console.log(files)
        // imageDataURI.encodeFromFile(files.filepath).then((res: any) => console.log(res)).catch((e: any) => console.log(e))
    })
})

What was the result you got?

{
  '': PersistentFile {
    _events: [Object: null prototype] { error: [Function (anonymous)] },
    _eventsCount: 1,
    _maxListeners: undefined,
    lastModifiedDate: 2022-01-07T08:18:45.682Z,
    filepath: '/var/folders/sw/g7tk44p50dl3n_kgss8y6bwr0000gn/T/351263a04127c47c7bf9c2800',
    newFilename: '351263a04127c47c7bf9c2800',
    originalFilename: 'Screenshot_2022-01-01_at_10.36.58_AM-removebg-preview.png',
    mimetype: 'image/png',
    hashAlgorithm: false,
    size: 51200,
    _writeStream: WriteStream {
      fd: 25,
      path: '/var/folders/sw/g7tk44p50dl3n_kgss8y6bwr0000gn/T/351263a04127c47c7bf9c2800',
      flags: 'w',
      mode: 438,
      start: undefined,
      pos: undefined,
      bytesWritten: 51200,
      closed: false,
      _writableState: [WritableState],
      _events: [Object: null prototype],
      _eventsCount: 1,
      _maxListeners: undefined,
      [Symbol(kFs)]: [Object],
      [Symbol(kIsPerformingIO)]: false,
      [Symbol(kCapture)]: false
    },
    hash: null,
    [Symbol(kCapture)]: false
  }
}

What result did you expect?

  • A Good Formatted JSON.
@gaurishhs gaurishhs added the bug label Jan 7, 2022
@GrosSacASac
Copy link
Contributor

The <input type="file"> should have a name property like <input type="file" name="something">

you well then be able to access it like so console.log(files.something?.filepath)

Also you are miss-using the word JSON

@tunnckoCore
Copy link
Member

@GrosSacASac true.

But definitely we should check against such case. 🚀 🚢

@GrosSacASac
Copy link
Contributor

Check what ?

@tunnckoCore
Copy link
Member

Ah, probably nothing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants