Upload large files using server side with restivus (Client is cUrl)


#1

My Meteor application need to get some big files from a scanner.
I have a software at the scanner side that can send the files using the curl command line.
My application expose some REST APIs using restivus, and the best is to continue using it for the file upload as well.

Process as I understand should be something like this:

  • Set REST API entry point with restivus that will handle the POST command
  • Use curl command line to send the file to the RESP API entry point
  • Access the file from within the POST handler and save it as FS object (or any other object. for now I will save it locally on the server. after upload will work, I will change to store on S3)

Reading the curl documentation, I figure out that there are some different ways to upload binary file:

  • curl --data-binary 'fileToStore:@myfile.jpg'
  • curl -F 'fileToStore:@myfile.jpg'
  • curl -T 'myfile.jpg'

  • How to send the file? (using curl)
  • With the --data-binary I can see the field using this.bodyParams.fileToStore
  • With the -F I’m not sure how to access the field. it is not part of the this.bodyParams.fileToStore, nor part of the request object
  • With the -T the curl add the file name to the URL, but I still can’t find the field in that new page.
  • How to process the file within restivus?
  • If I’m using the --data-binary option, would it work to use something like:
    var uploadedFile = new FS.File(this.bodyParams.fileToStore);
  • How to handle errors? (file size limit, canceled upload,…)