Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

curl: (26) couldn't open file

I am getting this error, when I am trying to call a box api through curl.

curl: (26) couldn't open file

Can't find why! I am calling this api with a correct file name-

curl https://upload.view-api.box.com/1/documents \
-H "Authorization: Token YOUR_API_TOKEN" \
-H "Content-type: multipart/form-data" \
-F file=@A_correct_file_name

I have seen all the three already asked questions but 2 of them are unanswered and one is specific to facebook.

cURL error 26 couldn't open file

Fatal error: Uncaught CurlException: 26: couldn't open file "" thrown in

Getting Fatal Error Uncaught CurlException: 26: couldn't open file

like image 310
halkujabra Avatar asked May 19 '14 05:05

halkujabra


4 Answers

I was having a similar problem after changing to PHP 5 (I was using the @ upload method and it was deprecated, so I had to start using CURLFile), and the solution to my problem was found in this stack.

Solution: curl upload won't work with relative paths, use the full path instead

like image 115
Guilherme Salomé Avatar answered Nov 14 '22 12:11

Guilherme Salomé


Sorry guys! My bad. I had not included extension of the file in the file name. After including it, it worked. I am answering this in case someone does the same mistake in future.

like image 42
halkujabra Avatar answered Nov 14 '22 11:11

halkujabra


For my case, using relative path didn't work. But changing it to a absolute path fixes it.

This failed

curl -i -X POST -H "Content-Type: multipart/form-data" \
    -F "file=@~/Downloads/xxx.csv" http://localhost:6708/upload

This worked

curl -i -X POST -H "Content-Type: multipart/form-data" \
    -F "file=@/Users/myself/Downloads/xxx.csv" http://localhost:6708/upload
like image 8
Edmund Lee Avatar answered Nov 14 '22 13:11

Edmund Lee


I was having this problem this morning but I solved with this

fileUpload=@\"file, with comma .txt\"

So you have to put some double quotes around the file name if you have commas in the file name ( \" )

like image 7
Luis Cruz Avatar answered Nov 14 '22 13:11

Luis Cruz