26

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

Community
  • 1
  • 1
halkujabra
  • 2,754
  • 3
  • 22
  • 35

7 Answers7

27

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

Community
  • 1
  • 1
Guilherme Salomé
  • 1,639
  • 4
  • 17
  • 38
19

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.

halkujabra
  • 2,754
  • 3
  • 22
  • 35
8

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
Edmund Lee
  • 2,406
  • 18
  • 27
7

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 ( \" )

Alex Karshin
  • 12,300
  • 14
  • 50
  • 60
Luis Cruz
  • 69
  • 1
  • 4
2

I had a similar problem with relative paths like @Guilherme did too. I was running my bash script with:

bash test/script.sh

However, my file was in the same directory level as the bash script and not the test directory (where I was calling bash from), so the script could not find my file.

Solution for me:
1. cd into /test and run bash script.sh from there
2. Use absolute paths

Kevin
  • 703
  • 2
  • 8
  • 17
1

I am using PlateRecognizer.com to secure license plate information from pics that I have isolated from videos from my dashcam. I was having so many problems with the exact code. PlateRecognizer did not provide the correct information in their help section.

I work using my Windows 10 laptop. This code is what finally worked for me:

curl -F upload=@/”Users/Me/Desktop/Driver1.mp4” -F regions=us-az -H “Authorization: Token 4892e779f97d879df6453” https://api.platerecognizer.com/v1/plate-reader/

Make note of the double quote marks around the file path and name - not single quote marks.

John Conde
  • 212,985
  • 98
  • 444
  • 485
0

Luis Cruz is correct: quotes are required around the filename, but I needed to use the 'file' keyword, not 'fileUpload', as is it shown in the question.

curl -X GET \
-H 'Content-Type: multipart/form-data' \
-F file=@"/path/to/file.ext" \ 
'http://host:port/path/to/dir'
Gapmeister66
  • 753
  • 7
  • 14