curl: (26) couldn't open file

2019-01-23 18:06发布

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

4条回答
做自己的国王
2楼-- · 2019-01-23 18:40

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

查看更多
Viruses.
3楼-- · 2019-01-23 18:48

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

查看更多
祖国的老花朵
4楼-- · 2019-01-23 18:53

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.

查看更多
我命由我不由天
5楼-- · 2019-01-23 18:59

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

查看更多
登录 后发表回答