AppApi-Module that adds a file endpoint

AppApiFile adds the /file endpoint to the AppApi routes definition. Makes it possible to query files via the api.

Current Version Current Version Current Version

Buy Me A Coffee

Relies on AppApi:

Installation


AppApiFile relies on the base module AppApi, which must be installed before AppApiFile can do its work.

AppApi and AppApiFile can be installed like every other module in ProcessWire. Check the following guide for detailed information: How-To Install or Uninstall Modules

The prerequisites are PHP>=7.2.0 and a ProcessWire version >=3.93.0 (+ AppApi>=1.2.0). However, this is also checked during the installation of the module. No further dependencies.

Features


You can access all files that are uploaded at any ProcessWire page. Call /file/route/in/pagetree?file=test.jpg to access a page via its route in the page tree. Alternatively you can call /file/4242?file=test.jpg (e.g.,) to access a page by its id. The module will make sure that the page is accessible by the active user.

The GET-param "file" defines the basename of the file which you want to get.

The following GET-params (optional) can be used to manipulate an image:

ParamValueDescription
widthint >= 0Width of the requested image
heightint >= 0Height of the requested image
maxWidthint >= 0Maximum Width, if the original image's resolution is sufficient
maxHeightint >= 0Maximum Height, if the original image's resolution is sufficient
cropXint >= 0Start-X-position for cropping (crop enabled, if width, height, cropX & cropY set)
cropYint >= 0Start-Y-position for cropping (crop enabled, if width, height, cropX & cropY set)

Use GET-Param format=base64 to receive the file in base64 format.

Pro tip: If you want to include an image from the api using the standard <img src=""> tag, it can be very difficult to include the api key and a token as headers. However, it is possible to include these values as GET parameters. The GET parameter with the apikey is called api_key. A token can be sent as parameter authorization.

Disclaimer: I recommend to use this solution only for this exceptional case. Generally headers are the better and more elegant solution.

Changelog


Changes in 1.0.6 (2022-06-01)

  • Bugfix throw 404 status if not found

Changes in 1.0.5 (2022-05-30)

  • Fix Webp support

Changes in 1.0.4 (2022-04-29)

  • Added support for Multi-Language URLS

Changes in 1.0.3 (2021-10-31)

  • Improved access to repeater images

Changes in 1.0.2 (2021-10-23)

  • Updated module infos

Changes in 1.0.1 (2021-10-23)

  • Smaller improvements in README

Changes in 1.0.0 (2021-10-21)

  • Added file endpoint
  • implemented different ways to access a page
  • implemented image-manipulation parameters

Versioning


We use SemVer for versioning. For the versions available, see the tags on this repository.

License


This project is licensed under the Mozilla Public License Version 2.0 - see the LICENSE.md file for details.

Install and use modules at your own risk. Always have a site and database backup before installing new modules.

Twitter updates

  • New post: Multi-language field translation export/import — In this post we cover the details of a new module that enables export and import capabilities for multi-language fields in ProcessWire… More
    5 August 2022
  • Weekly update, July 29: Continuing upgrades to ProcessWire’s comments system and FormBuilder, along with a working example—More
    29 July 2022
  • Weekly update for July 22– Looking back at what web development was like in the year 2000. Plus some more discussion on the path from CKEditor 4 to CkEditor 5 in ProcessWire: More
    22 July 2022

Latest news

  • ProcessWire Weekly #430
    In the 430th issue of ProcessWire Weekly we're going to check out some brand new third party modules, a new site of the week, and more. Read on!
    Weekly.pw / 7 August 2022
  • Multi-language field translation export/import
    In this post we cover the details of a new module that enables export and import capabilities for multi-language fields in ProcessWire.
    Blog / 5 August 2022
  • Subscribe to weekly ProcessWire news

“We chose ProcessWire because of its excellent architecture, modular extensibility and the internal API. The CMS offers the necessary flexibility and performance for such a complex website like superbude.de. ProcessWire offers options that are only available for larger systems, such as Drupal, and allows a much slimmer development process.” —xport communication GmbH