How to upload a csv file from local diretory using Curb library

71 Views Asked by At

I have been strugling for a few days to be able and manage file upload with curb library that is the ruby version of curl. The thing that was most worrying and blurry was the : " Curl::PostField.file" part where the documentation is kind of fuzzy at least to my eyes. The documentation says :

Curl::PostField.file(name, local_file_name) ⇒ #<Curl::PostField...>

Which does not say prety much anything by itself and it really does not work.

So the main idea is to figure out what goes in there in the file parameter, what is the "name" and what is the local_file_name ?

1

There are 1 best solutions below

0
On

So after too many tries the correct use is this :

Curl::PostField.file('filename','random_name'){IO.read(path)}

Ok the 'filename' is something you get from the html form and is important as a parameter. Each application may call this filename or image or .. whatever enter image description here

Now the second parameter filename is a dummy name that will be displayed as uploaded The path parameter is the location where this local file lives and can be a csv or.. image or.. etc.

Other than that uploading a form would likely use also more parameters that would be inserted with " Curl::PostField.content('param_name','param_value')" and can be easily be inspected within the html