Skip to content
/ i Public

My own image/file upload service

License

Notifications You must be signed in to change notification settings

zozs/i

Repository files navigation

i

i is an upload service over HTTP that you can run on your own server.

It is useful to, for example, easily upload screenshots from your computer to your own server, and get a short URL such as https://i.example.com/oYP59upc.png, which you can send to your friends over, e.g., chat or mail.

It works over HTTP, which makes it easy to upload files using different clients. It is also easy to both upload and download files from everywhere in the world, as long as you can make a regular HTTP connection. If desired, it uses HTTP Basic Authentication to ensure that not everyone can upload files to your server. Filenames are auto-generated random strings (by default), to avoid file enumeration. Optionally, you can also upload and keep the original filename.

Other features:

  • Provides a /recent page where you can see recent uploads
  • The recent page also provides thumbnails of upload for easier browsing

Bugs, feature requests, development

Bug tracker, mailing lists, and the canonical source code repo is hosted on Sourcehut https://sr.ht/~zozs/i/.

Compile

Run cargo build

Running (during development)

Run RUST_LOG=debug cargo run

Uploading files

Check the client-side directory in this repo for some examples on how files or screenshots can be uploaded to the server.

Note that you need to modify the server URL in each script to point to your own running instance.

The following examples are included:

  • screenshot-open.sh Take a screenshot of a selected area of the screen, upload it, and open the resulting URL in the default browser.
  • wayland-screenshot-open.sh The same as above, but uses grim and slurp instead, and works well in a Wayland environment.
  • screenshot.sh Take a screenshot of a selected area of the screen, upload it, and copy the resulting URL to the clipboard.
  • icp Upload a file from the terminal using icp file.txt, upload it, and open the resulting URL in the default browser.
  • upload-with-i.desktop Copy file to ~/.local/share/file-manager/actions/ to add "Upload with i" entry to the context menu in your file manager. Needs to be modified with the correct path to icp above, on the Exec line.
  • ios-shortcut.png An image describing an iOS shortcut that can be used from the Share menu on images and documents. Will upload to the server, and put the resulting URL in the clipboard, so that it can be pasted into an e-mail or text.

Using curl

Can be done using curl. The following command-line uploads a file testfile.txt in the current directory to the server. A random filename will be generated by the server and returned in the JSON object, as well as in a Location: header (since the response will be a 303 See Other upon success, unless configured otherwise, see below) Thus, in the example below, the uploaded file will be available at http://localhost:8088/Uake9Um7.txt.

$ curl -F [email protected] http://localhost:8088

{"url":"http://localhost:8088/Uake9Um7.txt"}

The following example will upload the same file, but will use the original filename instead, which can be seen in the response URL.

$ curl -F [email protected] -F options='{"useOriginalFilename":true}' http://localhost:8088

{"url":"http://localhost:8088/testfile.txt"}

Disabling redirect headers

For certain clients (e.g., iOS Shortcuts), it may be desirable to not have a Location header, or the 303 status code. If the option "redirect":false is added to the options object, the return code will instead be 200 OK, and there will be no Location header. The returned JSON object is the same, however.

$ curl -F [email protected] -F options='{"redirect":false}' http://localhost:8088

{"url":"http://localhost:8088/Uake9Um7.txt"}

Configuration

Set the following environmental variables to configure i. You can also set all settings by using arguments instead, such as i -P 1234 to change port. See i --help for details.

  • AUTH_USER: Set to the username for basic auth if you want to require authentication to upload files. Empty means no authentication.
  • AUTH_PASS: Set to the password for basic auth if you want to require authentication to upload files. Empty means no authentication.
  • BASE_DIR: Set to the file system directory where uploaded files will be stored to and served from. Default ./tmp.
  • SERVER_URL: Set to the complete server URL base which should be used when generating links. Default: http://localhost:8088.
  • PORT: Which port i should listen to. Default 8088.
  • RECENTS: How many entries to show in the list of recent uploads at the /recent endpoint (default: 15)
  • THUMBNAIL_SIZE: The width and height in pixels for the generated thumbnails (default: 150)

Set RUST_LOG to a valid EnvFilter string to customize tracing. Example RUST_LOG="i=info,[request]=debug" to log requests too.