Skip to content
On this page

Storage Plugin Development

Path Rules

FileHelper::fresnsFileStoragePath($fileType, $usageType);

Command Word

The main program interacts with the storage plug-in through command words, so the storage plug-in mainly implements the following command words.

Command WordDescription
getUploadTokenGet Upload Token
uploadFileupload File
uploadFileInfoUpload File Information
getAntiLinkFileInfoGet information about anti-theft link file [one]
getAntiLinkFileInfoListGet information about anti-theft link file[Multiple]
getAntiLinkFileOriginalUrlGet the source file anti-theft link
logicalDeletionFilesLogical Deletion Files
physicalDeletionFilesPhysical Deletion Files

As for the function of file-related command words and parameter instructions, please refer to development support.

Upload Page

The access path to the plugin upload page is configured in the accessPath parameter of the plugin.json file for operators and users to upload files using the plugin page after configuration.

Since the Fresns API and editor use the basic form upload mode, there is a risk of timeout interruptions for large files. The storage plugin can provide an upload page that integrates JS-SDK on the plugin page to implement slicing and breakpoint uploads for large files.

Audio and video functions

  • Transcoding command word triggered reactively.
  • Such three tables as posts, comments, and conversation_messages shall be subscribed to when installing the plug-in. When there are any newly-added contents, trigger the transcoding command word and scan whether there are any audio/video files.
  • If there are any audios/videos and transcoding is not performed (transcoding_state = 1), execute transcoding.

Transcoding Configuration

  • As for videos of file type 2, execute transcoding according to the video_transcode key value in the configuration table.
  • As for audios of file type 3, execute transcoding according to the audio_transcode key value in the configuration table.

Transcoding Process

    1. Wait for the subscription function of the main program to trigger you (notification your command word of the table state you subscribed)
    1. Your command word is triggered. Inquire file content attachment with primaryId.
    • file_usages->file_type = 2 video, 3 audio
    • file_usages->table_name = table name
    • file_usages->table_column = column name, post, comment, conversation message, is ID
    • file_usages->table_id = primaryId
    • The procedure should suspend if there is no attachment.
    1. Inquire the transcoding state files->transcoding_state
    • 3.1 transcoding_state = 1 to be transcoded: the procedure continues;
    • 3.2 transcoding_state = 2 transcoding: transcoding is being performed and the procedure suspends;
    • 3.3 transcoding_state = 3 transcoded: transcoding is completed and the procedure suspends;
    • 3.4 transcoding_state = 4 transcoding failed and the procedure suspends;
    1. Execute transcoding and modify file subsidiary table field as transcoding_state = 2 at the same time.
    1. Accept the call-back notification from the cloud service provider.
    • 5.1 Transcoding performed successfully:
      • 5.1.1 Fill the transcoded file name into the files->path
      • 5.1.2 Fill the source file path before transcoding into files->original_path
      • 5.1.3 Replace the new file information (this step could be neglected if there is no relevant new information)
        • files->mime
        • files->extension
        • files->size
        • files->md5
        • files->sha
        • files->sha_type
      • 5.1.4 Modify the transcoding state as files->transcoding_state = 3
    • 5.2 Transcoding failed
      • 5.2.1 Modify the transcoding state as files->transcoding_state = 4
      • 5.2.2 If there are any other parameters or notes that failed to be transcoded, fill them into the files->transcoding_reason field.

File Information Structure

File Information

use App\Models\File;

Example of information
    "fid": "files > fid",
    "type": "files > type",
    "status": "files > is_enable",
    "substitutionImageUrl": "File expiration alert image",
    "sensitive": "files > is_sensitive",
    "name": "files > name",
    "mime": "files > mime",
    "extension": "files > extension",
    "size": "files > size",
    "md5": "files > md5",
    "sha": "files > sha",
    "shaType": "files > sha_type",
    "moreJson": {
        // files->more_json
    // Image Parameters
    "imageWidth": "files > image_width",
    "imageHeight": "files > image_height",
    "imageLong": "files > image_is_long",
    "imageDefaultUrl": "image_bucket_domain + files->path",
    "imageConfigUrl": "image_bucket_domain + files->path + image_thumb_config",
    "imageAvatarUrl": "image_bucket_domain + files->path + image_thumb_avatar",
    "imageRatioUrl": "image_bucket_domain + files->path + image_thumb_ratio",
    "imageSquareUrl": "image_bucket_domain + files->path + image_thumb_square",
    "imageBigUrl": "image_bucket_domain + files->path + image_thumb_big",
    // Video Parameters
    "videoTime": "files > video_time",
    "videoCoverUrl": "video_bucket_domain + file->video_cover",
    "videoGifUrl": "video_bucket_domain + files->video_gif",
    "videoUrl": "video_bucket_domain + files->path",
    // Audio Parameters
    "audioTime": "files > audio_time",
    "audioUrl": "audio_bucket_domain + files->path",
    // Document Parameters
    "documentUrl": "document_bucket_domain + files->path",
    "documentPreviewUrl": "Links after replacement by rule",
    // Audio and Video Parameter
    "transcodingState": "files > transcoding_state"

Link to Original File

use App\Models\File;


Released under the Apache-2.0 License