Files are an essential component of modern software applications. Social Plus provides a powerful file management system that enables you to easily handle different types of files, such as document files, videos, and audio files. In this section, we will introduce you to the concept of a file in Social Plus and provide an overview of file handling in Social Plus.
File Data
Property
Description
fileId
Root file key on cloud storage
fileUrl
HTTP link for file download
type
File type
createdAt
Date/time when a file is uploaded
updatedAt
Date/time when a file is updated
attributes
Information about the file
Upload Files
To upload a file to the system, you can use the Social Plus File Upload API provided by the SDK. The API allows you to upload a file to the Social Plus server by giving the file's data and the file metadata, such as the file name, file type, and file size. The SDK simplifies the process of uploading files by providing pre-built components that you can easily integrate into your application.
On Android, you can separately observe uploading states outside of the uploading method by using:
import { FileRepository, LoadingStatus } from'@amityco/js-sdk';constliveObject=FileRepository.createFile({ file,// https://developer.mozilla.org/en-US/docs/Web/API/FileonProgress: ({ currentFile, currentPercent }) => { },});liveObject.on('loadingStatusChanged', ({ newValue }) => {if (newValue ===LoadingStatus.Loaded) {console.log('The file is uploaded',liveObject.model); }});liveObject.on('dataError', (error) => {console.error('can not upload the file', error);});// upload videoconstliveObject=FileRepository.createVideo({ file,onProgress: ({ currentFile, currentPercent }) => { },});Refer to the file model for the description of the response after a successful file creation. If an error is encountered while creating the file, it will return the following errors:
//Attached file payload is too large{"status": "error","code": 500000,"message": "Payload too large."}// Unexpected error{"status": "error","code": 500000,"message": "Unexpected error"}
Version 6 and Beta(v0.0.1)
Retrieve Files
You can retrieve a file from Social Plus using the Social Plus File Retrieval API provided by the SDK. The API enables you to retrieve a file from the Social Plus server by supplying the file ID. The SDK streamlines the process of retrieving files by offering pre-made components that can be smoothly integrated into your app.
import { FileRepository } from'@amityco/js-sdk';let file;constliveObject=FileRepository.getFile(fileId);liveObject.on('dataUpdated', (updatedModel) => { file = updatedModel;});liveObject.on('dataError', (error) => {console.error('Can not get the file', error);});file =liveObject.model;
Delete Files
In addition to uploading and retrieving files, Social Plus provides a deleting function to delete a file that is no longer needed.