0

Use case - I have an embedded box that has two files

  1. One big file containing debug logs , user logs to assist in technical field issues. This big file is basically a zip file around 100 Mb.

  2. Another file - small file containing configuration - around 3 Kb.

My requirement is to post these files to a webServer.

Technology - In order to post this file, I am using libcurl.

My assumptions about Web Server - This might be a form containing file input type.

<form method="post" enctype="multipart/form-data">
 <div>
   <label for="file">Choose file to upload</label>
   <input type="file" id="file" name="Myfile" multiple>
 </div>
 <div>
   <button>Submit</button>
 </div>
</form>

Also, it might be running node server to handle the POST request.

Question

1) Is curl -F a best option here to post such files rather than curl -d or -d binary option?

2) Generally, do we have seperate forms for each file type for example technical field file and another form for configuration file?

if not, then is it a good idea to ask user to enter the input file tag name so that curl -F option can work accurately irrespective how a Webserver is setup? Basically, according to the example - myFile can be any name so is it a good idea to ask user to pass this name? What is the short or popular name for file tag name - Myfile? So that I can ask user to enter this information.

dexterous
  • 6,422
  • 12
  • 51
  • 99

1 Answers1

0

Realized that HTTP/HTTPS PUT method is the appropriate solution here. This way there is no need for form or formidable npm module. Here is the curl page for PUT - How to do a PUT request with curl?

var ciphers = [
    'AES128-SHA',
    'AES256-SHA'
].join(':');


var options = {
    key: fs.readFileSync('./key.pem'),
    cert: fs.readFileSync('./cert.pem'),
    ciphers: ciphers
};

https.createServer(options, function(req, res) 

    {

     if (req.method === 'PUT') 
       {
           // use file npm module to copy the file content here. 
             // like fs.write
           req.on('data', function(data)
            {
               // write data here ..       
            } 
        }
        });

Client Side -

Here is the command line to test it -

curl -k -X PUT -F "myfile=@/test/Test.png" https://192.162.1.19/

Here is the libcurl code to test it .

https://curl.haxx.se/libcurl/c/httpput.html

Remember to link using -lcurl

#gcc putCode.c -o putcode -lcurl 
#./putCode /test/Music/joy.mp3 joyful.mp3
dexterous
  • 6,422
  • 12
  • 51
  • 99