Download the PHP package filejet/filejet-php without Composer
On this page you can find all versions of the php package filejet/filejet-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download filejet/filejet-php
More information about filejet/filejet-php
Files in filejet/filejet-php
Package filejet-php
Short Description PHP library for communicating with FileJet service. FileJet handles upload of files to remote storage and is capable of simple image mutations.
License MIT
Informations about the package filejet-php
FileJet PHP library
Provides PHP wrapper for communication with FileJet API.
For integration with Symfony project visit filejet/filejet-bundle repository.
Installation
You can install FileJet PHP library easily via Composer:
Usage
You need Storage ID and API key to be able to communicate with FileJet API. You can find those at filejet.io after registration.
FileJet PHP library internally calls FileJet API via HttpClient. We have used for our implementation HTTPlug project so you can use any HTTP client you want. You can easily use it with php-http/guzzle6-adapter
by installing it via Composer (see below) or you can follow HTTPlug tutorial for registering any HTTP client you choose.
Setup your service:
The FileJet\FileJet
class provides few public methods which can be used for generating URL for public files (supports on the fly mutations for images), fetching signed URL for private files, generating signed instructions for uploading the file to FileJet and deleting the files from FileJet by providing the file identifier.
uploadFile(UploadRequest $request): UploadInstruction
This method generates the instructions for uploading the file to FileJet. FileJet\UploadInstructions
contain file identifier for the file which will be uploaded - you should store this information for further usage (eg. for generating the links or deleting the files). The object also contains upload format object with signed URL for uploading the file, HTTP method which should be used and suitable headers which need to be used within the upload request.
You can either upload your file via some PHP HTTP client (which you already have set up because of FileJet API communication) or as recommended you can upload the file asynchronously via JavaScript. You will use URL, headers and HTTP method from UploadFormat object and body will contain file you want to upload.
Within FileJet\Messages\UploadRequest
you need to specify mime type of file you want to upload, the accessibility of the file (public or private) eg. if you want the file to be publicly accessible via FileJet CDN (suitable for images) or you want to upload private file with sensitive information (suitable for documents) which will be accessible only for users with the correct Storage ID and API key. The last parameter is optional and it tells FIleJet for how long should the upload link be valid. Default value is 60 seconds.
For better performance we recommend upload files via JavaScript by fetching the upload format from FileJet API via your backend and provide these information to the frontend. Then you can simply use fetch
.
bulkUploadFiles(UploadRequest[] $requests): UploadInstruction[]
This method is useful when you want tu upload multiple files. It works exact the same like uploadFile()
but is more efficient than calling multiple times uploadFile()
.
The result UploadInstruction[]
is ordered in the same order as the input UploadRequest[]
. Default php array keys are used.
getUrl(FileInterface $file): string
When you upload file with public accessibility eg. you will use FileJet\Messages\UploadRequest::PUBLIC_ACCESS
while fetching upload format you can access your files via FileJet CDN. This method will generate the publicly accessible link for your files based on your configuration.
Method accepts only argument the object which describes your file. You can use this method with FileJet\File
object which implements FileJet\FileInterface
. The object contains file identifier provided by uploadFile()
method. If you are trying to get link for image you can optionally provide mutation string (see documentation). For SEO purposes you can provide the optional third argument which will append the file URL with your custom name.
getPrivateUrl(string $fileId, int $expires): DownloadInstruction
After uploading file to private storage you can retrieve download link by this method. You just need to provide file identifier as first argument. The second argument specifies the number of seconds when the link is valid eg. its expiration time.
getExternalUrl(string $url, string $mutation)
You don't need to upload files through FileJet service in order to use all of its functionality, You can use all mutations with your own images.
Simply use this method for your publicly accessible images with use of FileJet mutations. In order for this method to work you will need either add the domain from which you are serving your images to the whitelist or you can provide signatureSecret
to your configuration.
You can manage the whitelist and your signatureSecret
at https://app.filejet.io
deleteFile(string $fileId): void
This method will delete file from FileJet. The only argument is file identifier obtained from uploadFile()
method.
Auto optimization mode
You can use our intelligent auto optimization mode by simply activate it globally by setting a third argument of FileJet\Config
to true
. This will append every public URL with auto
mutation which is responsible for providing most optimized version of your image to your clients.
If you don't want to use auto mode globally you can append at any time to your images by simply providing auto
mutation string.
If you are using auto optimization mode globally and you for any reason want to disable it for specific images, you can disable it per image by providing auto=false
mutation.
All versions of filejet-php with dependencies
psr/http-message Version ^1.0
php-http/client-implementation Version ^1.0
php-http/httplug Version ^1.0|^2.0
php-http/message-factory Version ^1.0
php-http/discovery Version ^1.0
aws/aws-sdk-php Version ^3.238.2
ext-json Version *