Malformed stream when uploading file to Box

New Contributor

Malformed stream when uploading file to Box

var axios = require('axios');
    var data = '\n--------------------------foo_bar_baz\ncontent-disposition: form-data; name="attributes"\n\n{"name":"ENC-mob.key.lock", "parent":{"id":"115921805292"}}\n--------------------------foo_bar_baz\ncontent-disposition: form-data; name="file"; filename="ENC-mob.key.lock"\ncontent-type: text/plain\n\n1\n\n--------------------------foo_bar_baz--';

    var config = {
      method: 'post',
      url: '',
      headers: { 
        'Content-Type': 'multipart/form-data; boundary=------------------------foo_bar_baz',
        'Authorization': 'Bearer ' + this.credentials.access_token,
      data : data
    console.log("Data: " + _params);
    try {
      let response: any = await axios(config)
      return response;
    } catch(error) {
      console.log(error + "\nError Message: " + error.message + "\nError response: " + JSON.stringify(error.response));
      return error;


I am trying to upload a file to Box drive using its upload API, but I get Malformed Stream error response. I cannot figure out why?


Tags (1)
Box Employee

Re: Malformed stream when uploading file to Box

For this one I'd recommend reading the file directly from a file source, rather than inputting the content of the file directly as a string. 


- Jon