Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting ERR_FS_FILE_TOO_LARGE while using unirest file send with put

I am using unirest to upload a file like so

 unirest.put(fullUri)
    .auth({
      user: self.userName,
      pass: self.password
    })
    .header('X-Checksum-Sha1', sha1Hash)
    .header('X-Checksum-Md5', md5Hash)
    .send(fs.readFileSync(filePath))
    .end(function (response) {

This works fine for smaller files but for large files I get ERR_FS_FILE_TOO_LARGE error. I have already tried max_old_space_size without success. Looks like I can fix this by streaming the file but I can't find an api to do that in unirest js library.

like image 391
parapura rajkumar Avatar asked Jul 10 '20 13:07

parapura rajkumar


1 Answers

Looks like this is an issue with form-data From GitHub Issues


It turns out that the unirest are using the NPM module form-data, and the form-data module requires that if it received a stream that not fs.ReadStream, we need to provide the file information by additional.

Example:

form.append( 
  'my_file', 
  stream,
  {
    filename: 'bar.jpg', 
    contentType: 'image/jpeg', 
    knownLength: 19806,
  },
)

See: https://github.com/form-data/form-data#void-append-string-field-mixed-value--mixed-options-

like image 194
Artistan Avatar answered Nov 15 '22 03:11

Artistan