{"id":21803017,"url":"https://github.com/litongjava/openfile-server","last_synced_at":"2026-05-08T17:34:02.700Z","repository":{"id":185714559,"uuid":"669595059","full_name":"litongjava/openfile-server","owner":"litongjava","description":"openfile-server","archived":false,"fork":false,"pushed_at":"2025-03-03T06:51:31.000Z","size":136,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-03T07:29:48.259Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/litongjava.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-07-22T19:41:58.000Z","updated_at":"2025-03-03T06:51:35.000Z","dependencies_parsed_at":null,"dependency_job_id":"c6a0faa6-6792-402a-a2fe-e828d9d48db5","html_url":"https://github.com/litongjava/openfile-server","commit_stats":null,"previous_names":["litongjava/openfile-server"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/litongjava%2Fopenfile-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/litongjava%2Fopenfile-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/litongjava%2Fopenfile-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/litongjava%2Fopenfile-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/litongjava","download_url":"https://codeload.github.com/litongjava/openfile-server/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244752362,"owners_count":20504256,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-27T11:37:14.105Z","updated_at":"2026-05-08T17:34:02.687Z","avatar_url":"https://github.com/litongjava.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# openfile-server\n\n## introduction\n\n1.upload file   \n2.download file  \n3.file list\n\n## install\n### docker\n```\ndocker build -t litongjava/openfile-server:1.0.0 .\n```\n\nrun\n\n```\ndocker run -dit --name=openfile-server -p 8080:80 litongjava/openfile-server:1.0.0\n```\n### cmd\n```shell\nsudo apt-get update\nsudo apt-get install libwebp-dev -y\nsudo apt-get install gcc -y\nsudo apt-get install ffmpeg -y\nCGO_ENABLED=1 go build\n```\n错误\n```shell\nlink: github.com/bytedance/sonic/ast: invalid reference to encoding/json.safeSet\n```\n解决办法\n```shell\ngo get -u github.com/bytedance/sonic\n```\nrun\n```shell\n/data/apps/openfile-server/openfile-server\n```\n### openfile-server.service\n\n```\nvi /lib/systemd/system/openfile-server.service\n```\n\n```\n[Unit]\nDescription=HTTP Server\nAfter=network.target\n\n[Service]\nType=simple\nUser=root\nRestart=on-failure\nRestartSec=5s\nWorkingDirectory=/data/apps/openfile-server\nExecStart=/data/apps/openfile-server/openfile-server\n\n[Install]\nWantedBy=multi-user.target\n```\n\n````\nsystemctl enable openfile-server\nsystemctl start openfile-server\nsystemctl status openfile-server\nsystemctl restart openfile-server\n```\n\n### 配置nginx\n/etc/nginx/common_file_locations.conf\n```shell\n# thumbnail\nlocation ~* /file/(.*)_(\\d+)x(\\d+)\\.(jpg|jpeg|png|gif)$ {  \n  proxy_pass http://file_server;\n  proxy_pass_header Set-Cookie;\n  proxy_set_header Host $host:$server_port;\n  proxy_set_header X-Real-IP $remote_addr;\n  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n  proxy_set_header X-Forwarded-Proto $scheme;\n  proxy_set_header Upgrade $http_upgrade;\n  proxy_set_header Connection \"upgrade\";\n  error_log  /var/log/nginx/backend.error.log;\n  access_log  /var/log/nginx/backend.access.log;\n}\nlocation /file {\n  # 处理 OPTIONS 请求\n  if ($request_method = 'OPTIONS') {\n    add_header Access-Control-Allow-Origin *;\n    add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';\n    add_header Access-Control-Allow-Headers 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';\n    add_header Content-Length 0;\n    add_header Content-Type text/plain;\n    return 204;\n  }\n\n  add_header Access-Control-Allow-Origin *;\n  add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';\n  add_header Access-Control-Allow-Headers 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';\n  add_header Access-Control-Expose-Headers 'Content-Length,Content-Range';\n  \n  root /data/apps/openfile-server;\n  \n  # 开启缓存\n  proxy_cache file_cache;\n  proxy_cache_valid 200 1h;\n  proxy_cache_valid 404 1m;\n  add_header X-Cache-Status $upstream_cache_status;\n}\n\n\nlocation /s {\n  root /data/apps/openfile-server;\n  autoindex on;\n  autoindex_exact_size on;\n  autoindex_localtime on;\n  charset utf-8,gbk;\n}\n  \nlocation /ping {\n  proxy_pass http://file_server;\n  proxy_pass_header Set-Cookie;\n  proxy_set_header Host $host:$server_port;\n  proxy_set_header X-Real-IP $remote_addr;\n  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n  proxy_set_header X-Forwarded-Proto $scheme;\n  proxy_set_header Upgrade $http_upgrade;\n  proxy_set_header Connection \"upgrade\";\n  error_log  /var/log/nginx/backend.error.log;\n  access_log  /var/log/nginx/backend.access.log;\n}\n\nlocation /upload {\n  proxy_pass http://file_server;\n  proxy_pass_header Set-Cookie;\n  proxy_set_header Host $host:$server_port;\n  proxy_set_header X-Real-IP $remote_addr;\n  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n  proxy_set_header X-Forwarded-Proto $scheme;\n  proxy_set_header Upgrade $http_upgrade;\n  proxy_set_header Connection \"upgrade\";\n  error_log  /var/log/nginx/backend.error.log;\n  access_log  /var/log/nginx/backend.access.log;\n}\n\nlocation /uploadImg {\n  proxy_pass http://file_server;\n  proxy_pass_header Set-Cookie;\n  proxy_set_header Host $host:$server_port;\n  proxy_set_header X-Real-IP $remote_addr;\n  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n  proxy_set_header X-Forwarded-Proto $scheme;\n  proxy_set_header Upgrade $http_upgrade;\n  proxy_set_header Connection \"upgrade\";\n  error_log  /var/log/nginx/backend.error.log;\n  access_log  /var/log/nginx/backend.access.log;\n}\n\nlocation /uploadVideo {\n  proxy_pass http://file_server;\n  proxy_pass_header Set-Cookie;\n  proxy_set_header Host $host:$server_port;\n  proxy_set_header X-Real-IP $remote_addr;\n  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n  proxy_set_header X-Forwarded-Proto $scheme;\n  proxy_set_header Upgrade $http_upgrade;\n  proxy_set_header Connection \"upgrade\";\n  error_log  /var/log/nginx/backend.error.log;\n  access_log  /var/log/nginx/backend.access.log;\n}\n\nlocation /uploadMp3 {\n  proxy_pass http://file_server;\n  proxy_pass_header Set-Cookie;\n  proxy_set_header Host $host:$server_port;\n  proxy_set_header X-Real-IP $remote_addr;\n  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n  proxy_set_header X-Forwarded-Proto $scheme;\n  proxy_set_header Upgrade $http_upgrade;\n  proxy_set_header Connection \"upgrade\";\n  error_log  /var/log/nginx/backend.error.log;\n  access_log  /var/log/nginx/backend.access.log;\n}\n\nlocation /uploadDoc {\n  proxy_pass http://file_server;\n  proxy_pass_header Set-Cookie;\n  proxy_set_header Host $host:$server_port;\n  proxy_set_header X-Real-IP $remote_addr;\n  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n  proxy_set_header X-Forwarded-Proto $scheme;\n  proxy_set_header Upgrade $http_upgrade;\n  proxy_set_header Connection \"upgrade\";\n  error_log  /var/log/nginx/backend.error.log;\n  access_log  /var/log/nginx/backend.access.log;\n}\n```\n\n```shell\nupstream file_server {\n  server 127.0.0.1:9000;\n}\nproxy_cache_path /var/cache/nginx levels=1:2 keys_zone=file_cache:10m max_size=10g inactive=60m use_temp_path=off;\n\nserver {\n  listen 8568;\n  server_name localhost;\n  index index.htm index.html;\n\n  include common_file_locations.conf;\n}\n```\n\n## usage\n\nupload file\n\n```shell\ncurl http://localhost:8080/upload/litongjava/images/ -F file=@\"q4.png\"\n```\n\nfile list\n\n```\nhttp://localhost:8080/s/\n```\n\n## Thumbnail Configuration - Using Nginx `image_filter` Module\n\nThis document explains how to use Nginx's `image_filter` module to dynamically generate image thumbnails by specifying width and height in the request.\n\n### 1. Check if the `image_filter` module is installed\n\nTo handle image resizing in Nginx, the `image_filter` module is required. You can check if this module is installed with the following command:\n\n```bash\nnginx -V 2\u003e\u00261 | grep image_filter\n```\n\nIf the output includes `--with-http_image_filter_module`, the module is installed. If not, you can recompile Nginx with this module enabled or use the official precompiled package provided by Nginx.\n### 2. load ngx_http_image_filter_module\n```cgo\n--with-http_image_filter_module=dynamic\n```\nif dynamic please load module\n```cgo\nload_module modules/ngx_http_image_filter_module.so;\n\n```\n### 3. Nginx Configuration\n\nBelow is an example configuration using the `image_filter` module to resize images:\n\n```nginx\nlocation ~* /file/(.*)_(\\d+)x(\\d+)\\.(jpg|jpeg|png|gif)$ {\n  # Extract the image name, width, and height\n  set $image_name $1;\n  set $width $2;\n  set $height $3;\n\n  # Apply image resizing\n  image_filter resize $width $height;\n  \n  # Set JPEG quality to 70 to reduce file size (default is 75)\n  image_filter_jpeg_quality 70;\n\n  # Configure buffer size to avoid memory overflow when processing large images\n  image_filter_buffer 100M;\n\n  # Set the returned image type based on the file extension\n  default_type image/$4;\n\n  # Use alias instead of root to match the actual image path\n  alias /data/apps/openfile-server/file/$image_name.$4;\n}\n```\n\n#### Explanation:\n\n- **location matching rule**: Matches image requests starting with `/file/`, where the name includes width and height parameters (e.g., `_100x100`). In the regular expression, `$1` represents the image name, `$2` and `$3` represent width and height, and `$4` represents the image extension (`jpg`, `jpeg`, `png`, `gif`).\n\n- **`set` directive**: Assigns the captured groups from the regular expression to `$image_name` (original image name), `$width` (width), and `$height` (height).\n\n- **`image_filter resize`**: Uses the `image_filter` module to resize the image to the specified width and height.\n\n- **`image_filter_jpeg_quality`**: Adjusts the JPEG image compression quality. It's set to 70 here to balance image quality and file size.\n\n- **`image_filter_buffer`**: Specifies the buffer size to prevent memory overflow when processing large images. A larger value, such as `100M`, is recommended.\n\n- **`default_type`**: Returns the correct `MIME` type based on the image extension, ensuring the browser renders the image correctly.\n\n- **`alias` directive**: Maps to the actual image path on the server using `alias` instead of `root` to avoid path confusion. In this case, images are stored in the `/data/apps/openfile-server/file/` directory.\n\n### 4. Testing Access\n\nYou can test the setup using the following URLs:\n\n- **Original image access**:  \n  `http://192.168.3.9:8568/file/images/200-dpi.png`\n\n- **Thumbnail access (100x100 size)**:  \n  `http://192.168.3.9:8568/file/images/200-dpi_100x100.png`\n\n### 5. Notes\n\n- The `image_filter` module dynamically processes images, which may consume significant CPU and memory resources, especially in high-concurrency environments. It is recommended to implement a caching mechanism or pre-generate thumbnails to reduce server load.\n- For large-scale image resizing, consider caching frequently used thumbnails in a CDN or on disk to further reduce server load.\n\nWith this configuration, Nginx can dynamically generate thumbnails based on the requested width and height, allowing users to access images in different sizes efficiently.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flitongjava%2Fopenfile-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flitongjava%2Fopenfile-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flitongjava%2Fopenfile-server/lists"}