raszi / node-tmp

Temporary file and directory creator for node.js
MIT License
737 stars 93 forks source link

No such file or directory error when creating file to be used in read stream in previously working code. #153

Closed LukeDouglas closed 7 years ago

LukeDouglas commented 7 years ago

Operating System

NodeJS Version

Tmp Version

0.33, 0.32 0.31, 0.30 all tried with the same issue.

Expected Behavior

Expecting to create a file and set its path to a variable using the tmpNameSync method. The created file was to be turned into a readstream to be sent as a form field as part of a request-promise request. Code Snippit to follow:

let rp = require('request-promise');
let tmp = require('tmp');

var options = {
        url: `https://hookb.in/ZRQDRWxl`
    };

 var req = rp(options);
 var form = req.form();
 var name = tmp.tmpNameSync({
       "postfix": ".json"
    });

  form.append('metaData', JSON.stringify({
        "format": "json"
    }))
    var stream = fs.createReadStream(name)
    form.append('file', stream)

return req.
then(r=>(console.log(r)))
.catch(error =>console.log(error))

The above code was operating as expected without errors as of 8/15/17.

Experienced Behavior

Request promise is unable to find the file at the path provided by tmpNameSync and it responds with the following error:

Error: form-data: ENOENT: no such file or directory, open '/tmp/tmp-33997fpJUVlfsoqMS.json'

raszi commented 7 years ago

Hi Lukas,

I don't think this was ever worked before since you are asking for a name only with tmpNameSync and not a file with fileSync.

LukeDouglas commented 7 years ago

Thank you for the feedback, changing tmpNameSync to fileSync fixed the issue. I do want to confirm that this code was working last week and for the previous month as written above. I understand now that the syntax was incorrect and it should not have worked but it was functional for some time. Thank you again for your feedback.

raszi commented 7 years ago

You can check the source of tmpNameSync it did not change recently, so the change must have been somewhere else.