Uploading a file using curl command is not working

1. The problem I’m having:

I am trying file upload a file (test3.txt) to caddy file server (caddy:2.6.4-alpine). The command i am using is as below,
curl -T test3.txt -X PUT “http://localhost:8089/” -vvv

I have given all permissions required,

caddy$ ll test3.txt site*
-rw-rw-r-- 1 abjyoti abjyoti 0 May 11 09:54 test3.txt

site:
total 24
drwxrwxrwx 3 abjyoti abjyoti 4096 May 10 13:09 ./
drwxrwxr-x 8 abjyoti abjyoti 4096 May 11 09:54 …/
-rwxrwxrwx 1 abjyoti abjyoti 565 May 10 08:01 caddy.json*
drwxrwxrwx 2 abjyoti abjyoti 4096 May 10 13:09 dir_a/
-rwxrwxrwx 1 abjyoti abjyoti 31 May 10 07:15 test2.txt*
-rwxrwxrwx 1 abjyoti abjyoti 31 May 10 07:12 test.txt*

2. Error messages and/or full log output:

Error log on console:
caddy$ curl --noproxy “*” -T test3.txt -X PUT “http://localhost:8089/” -vL

  • Trying 127.0.0.1:8089…
  • Connected to localhost (127.0.0.1) port 8089 (#0)

PUT /test3.txt HTTP/1.1
Host: localhost:8089
User-Agent: curl/7.81.0
Accept: /
Content-Length: 0

  • Mark bundle as not supporting multiuse
    < HTTP/1.1 404 Not Found
    < Server: Caddy
    < Date: Thu, 11 May 2023 10:09:49 GMT
    < Content-Length: 0
    <
  • Connection #0 to host localhost left intact

I am getting the debug log as below in the caddy server,

2023/05/11 10:09:49.240 DEBUG http.handlers.file_server sanitized path join {“site_root”: “/site”, “request_path”: “/test3.txt”, “result”: “/site/test3.txt”}
2023/05/11 10:09:49.240 DEBUG http.log.error {id=ucbfrf2cs} fileserver.(FileServer).notFound (staticfiles.go:601): HTTP 404 {“request”: {“remote_ip”: “172.17.0.1”, “remote_port”: “59014”, “proto”: “HTTP/1.1”, “method”: “PUT”, “host”: “localhost:8089”, “uri”: “/test3.txt”, “headers”: {“User-Agent”: [“curl/7.81.0”], “Accept”: ["/*"], “Content-Length”: [“0”]}}, “duration”: 0.000180767, “status”: 404, “err_id”: “ucbfrf2cs”, “err_trace”: “fileserver.(*FileServer).notFound (staticfiles.go:601)”}

2023/05/11 10:09:49.240 DEBUG   http.handlers.file_server       sanitized path join     {"site_root": "/site", "request_path": "/test3.txt", "result": "/site/test3.txt"}
2023/05/11 10:09:49.240 DEBUG   http.log.error  {id=ucbfrf2cs} fileserver.(*FileServer).notFound (staticfiles.go:601): HTTP 404 {"request": {"remote_ip": "172.17.0.1", "remote_port": "59014", "proto": "HTTP/1.1", "method": "PUT", "host": "localhost:8089", "uri": "/test3.txt", "headers": {"User-Agent": ["curl/7.81.0"], "Accept": ["*/*"], "Content-Length": ["0"]}}, "duration": 0.000180767, "status": 404, "err_id": "ucbfrf2cs", "err_trace": "fileserver.(*FileServer).notFound (staticfiles.go:601)"}

3. Caddy version:

Version of caddy docker image: caddy:2.6.4-alpine sh

4. How I installed and ran Caddy:

Following are the steps used to deploy the caddy server;

sudo ufw allow 8089
sudo ufw allow 2019
docker run -d -it -p 8089:8089 -p 2019:2019 -p 2020:2020
-v ./site:/site
-v ./caddy_data:/data
-v ./caddy_config:/config
-v ./Caddyfile:/etc/caddy/Caddyfile
-v ./static:/static
–name caddyserver
caddy:2.6.4-alpine sh

docker exec -it caddyserver caddy adapt --config /etc/caddy/Caddyfile
docker exec -d -it caddyserver caddy run --config /etc/caddy/Caddyfile
docker logs caddyserver -f

a. System environment:

Host OS: Ubuntu 22.04 LTS Server

Version of caddy docker image: caddy:2.6.4-alpine sh

b. Command:

curl --noproxy "*" -T test3.txt -X PUT "http://localhost:8089/" -vL

c. Service/unit/compose file:

d. My complete Caddy config:

{
        admin :2019
        auto_https off
        debug
}
:8089 {
        root * /site
        file_server browse
}

5. Links to relevant resources:

The file_server delivers only file and does not offer a option to upload files, afaik.

You can try to use the Upload module Image for uploading a file.

Thanks for your quick reply and help. Now i am exploring the suggested option.

Will the “Upload module Image” is super set of “file_server” ? Or i require to run that separately for file upload.

If there is anyway to make the upload work with this docker images, it would be of great help.

Will the “Upload module Image” is super set of “file_server” ?

No. file server and upload module are two different modules.

Or i require to run that separately for file upload.

The file server is part of caddy so you have both modules in the same binary and can be configured with standard caddy file directive.
A example config is in the git repo caddyv2-upload/docker-files/opt/webroot/config/Caddyfile-upload-test at main · git001/caddyv2-upload · GitHub or caddyv2-upload/docker-files/opt/webroot/config/Caddyfile-upload.json at main · git001/caddyv2-upload · GitHub

If there is anyway to make the upload work with this docker images, it would be of great help.

This question was answered in the above answer

You can try to use the Upload module Image for uploading a file.

If i understand correctly, by using the correct (example json from caddyv2-upload/Caddyfile-upload-test at main configuration file, it is possible to enable the upload feature even with caddy:2.6.4-alpine docker image.

Appreciate your help and support.

Well if in the caddy:2.6.4-alpine is the upload module compiled in then yes.
I not can you use the Image from docker hub above.

1 Like

Thanks Aleks, i will try and check if the “upload module” is supported in caddy:2.6.4-alpine container image, before i switch to caddyv2-upload image.

Just an update: “upload module” will not come with caddy as it is not standard.

**This module does not come with Caddy.** It can be added by using **[xcaddy](https://caddyserver.com/docs/build#xcaddy)** or our **[download page](https://caddyserver.com/download)** . Non-standard modules may be developed by the community and are not officially endorsed or maintained by the Caddy project. The documentation is shown here only as a courtesy.

Uploading functionality is not included in vanilla Caddy, so you need to use a plugin to get that functionality.

See the docs on Docker Hub, you can make your own custom build of Caddy with whatever plugins you need, there’s an example Dockerfile using the builder image variant.

We recommend building it yourself (instead of other people’s pre-built images on docker hub) because it gives you control over your own custom build (you can add more plugins as you like) and avoids security risks such as the maintainer pushing a malicious build.

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.