question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Value in append(field, value, options) is set to null

See original GitHub issue

I am trying to associate a filename with a JSON object and post a multipart request. I don’t know why I am getting this error. Options is set and value is just a JSON string. Reproducible test program is included here.

node_modules\form-data\lib\form_data.js:226 } else if (options.filename || value.name || value.path) {
TypeError: Cannot read property ‘name’ of null

const request = require('request');
const FormData = require('form-data');

var options = {
  filename: 'test.json',
  contentType: 'application/json'
};

var json = {
  text: 'hello world'
};

var form = new FormData();
form.append('file', JSON.stringify(json), options);
console.log(JSON.stringify(form, null, 2));

var username = 'username',
    password = 'password',
    url = 'https://' + username + ':' + password + '@somewhere.com';

request.post({
    url: url,
    formData: form
  },
  function optionalCallback(err, httpResponse, body) {
    if (err) {
      return console.error('upload failed:', err);
    }
    console.log('Upload successful!  Server responded with:', body);
  }
);

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:4
  • Comments:7

github_iconTop GitHub Comments

1reaction
kittaakoscommented, Feb 18, 2019

What I meant is that’s not a ‘workaround’, that’s just the way to use it.

you don’t require(‘form-data’) in your code… you require(‘request’) which uses form-data internally.

Thank you for the clarification, @aacotroneo!

The example from form-data confused me.

0reactions
aacotroneocommented, Feb 18, 2019

if it’s not clear… you don’t require(‘form-data’) in your code… you require(‘request’) which uses form-data internally… and you just pass an plain js object.

Read more comments on GitHub >

github_iconTop Results From Across the Web

JQuery append value set null before setting another
Here I'm doing is split value in the href and set that value to modal-header . Then I again do that it shows...
Read more >
Append (Data Management)—ArcGIS Pro | Documentation
ArcGIS geoprocessing tool that appends multiple input datasets into an existing target dataset.
Read more >
Modifying table schemas | BigQuery - Google Cloud
When you add new columns during an append operation, the values in the new columns are set to NULL for existing rows. To...
Read more >
How To: Replace null values with zeroes in an attribute table ...
Loop through the fields, and determine the count for the values. for field in fieldObs: fieldNames.append(field.name) del fieldObs fieldCount = ...
Read more >
Add, select, or clear items | Select2 - The jQuery replacement ...
Set the value, creating a new option if necessary if ... by default var newOption = new Option(data.text, data.id, true, true); // Append...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found