imageserve icon indicating copy to clipboard operation
imageserve copied to clipboard

Docker support + improve url handling

Open fugidev opened this issue 4 years ago • 0 comments

Since many people (including me) were struggling with setting this up correctly, I decided to create a docker configuration so it can be deployed more easily. Bare metal deployment is still 100% possible like before, for those who need/prefer that.

When the image is built, the normal config.php is replaced with another one that uses environment variables. This way, you can configure everything at run time. Simply uncomment the variables you need. Flags like RAW_IMAGE_LINK will become true if the variable is set to anything (actual boolean values are not supported).
I also added a variable to easily change the upload_max_filesize in php.ini (default is 64M now instead of 2M).

The images directory is a bind mounted external folder, and the exposed port for http will be 8080 by default. You can easily change this as you want, but the better alternative would be to disable the port completely and put the container behind a reverse proxy with https instead (system nginx, another container, ...).

To deploy, all you need to do is clone, edit docker-compose.yml and execute this:

docker-compose build
docker-compose up -d

... or docker-compose up -d --build for short. No need to touch config.php or php.ini to get get it running.


Along the way I noticed that the way urls are handled in .htaccess and upload.php is very hit-and-miss / only works for a very specific configuration and breaks in unexpected ways otherwise. So I made that more consistent and "robust" overall:

  • return the actual http code on error - ShareX can't detect errors otherwise
  • make the file hash unique across all file types
  • if the file extension is omitted in the url, "guess" the type by looking in every folder
  • the regular url path that upload.php returns will now be just the hash (+ extension), so the full url would be something like <hostname>/s7nHl, consistently for all file types
  • RAW_IMAGE_LINK was completely broken (it returned the absolute path on the server's filesystem), works as intended now
  • all file types can be accessed like /s7nHl, /s7nHl.png, /p/s7nHl, /p/s7nHl.png or direct link, so these changes should be 100% backwards compatible (for existing shared links)
Also I suggest using this custom uploader config in ShareX (this way all kinds of url the server returns should work fine)
{
  "Version": "13.5.0",
  "Name": "imageserve",
  "DestinationType": "ImageUploader, FileUploader",
  "RequestMethod": "POST",
  "RequestURL": "[hostname]/upload.php",
  "Body": "MultipartFormData",
  "Arguments": {
    "password": "[your password]"
  },
  "FileFormName": "image",
  "RegexList": [
    "success,(.*)$"
  ],
  "URL": "[hostname]/$regex:1|1$"
}

fugidev avatar Jul 26 '21 00:07 fugidev