social.plus provides a robust file management system that enables seamless handling of various file types including documents, media files, and attachments. This guide covers comprehensive file operations with practical examples across all supported platforms.
File Size Limits: Maximum file size is 1 GB per upload. Larger files should be chunked or compressed before upload.

Key Features

Universal File Support

Handle documents, media files, and attachments of all types

Progress Tracking

Real-time upload progress with automatic retry mechanisms

CDN Delivery

Optimized global delivery through content distribution network

Secure Storage

Enterprise-grade security with access control and encryption

File Properties

The file object contains comprehensive metadata and tracking information:

File Attributes Structure

The attributes object provides detailed file information including format-specific metadata:
{
  "name": "document.pdf",
  "extension": "pdf",
  "size": 2048576,
  "mimeType": "application/pdf",
  "metadata": {
    "duration": 120, // For video/audio files
    "dimensions": {  // For image files
      "width": 1920,
      "height": 1080
    }
  }
}

File Upload

Upload files to social.plus with progress tracking and error handling. The SDK provides optimized upload with automatic retry and resumable uploads for large files.
Large files are automatically chunked and uploaded with resume capability, ensuring reliable delivery even on unstable connections.
// Note: fileUrl must be a local file url.
func uploadFileExample(fileUrl: URL, fileName: String) async {
    do {
        let file = try await fileRepository.uploadFile(with: fileUrl, fileName: fileName, progress: { progress in
            print("uploading progress: \(progress)")
        })
        print("uploading finish successfully: fileId \(String(describing: file.fileId))")
    } catch {
        // Handle error here
    }
}

File Retrieval

Retrieve uploaded files using their unique file ID. The SDK provides efficient caching and optimized delivery through CDN.
Files are automatically cached and delivered through our global CDN for optimal performance worldwide.
let fileRepository = AmityFileRepository(client: client)

do {
    // Get AmityRawFile
    let rawFile = try await fileRepository.getFile(fileId: "<file-id>")
    
    // Transform AmityRawFile to specific AmityFileData.
    // If AmityRawFile is not the type `file`, it will return nil.
    if rawFile.type == .file {
        guard let fileData = rawFile.mapToFileData() else {
            return
        }
        
        // Download the file by using downloadFile api or
        // You can use any network client to download the file.
        let path = try await fileRepository.downloadFile(fromURL: fileData.fileURL)
        print("File downloaded to local path: \(path)")
    }
} catch {
    // Handle error here
}

File Deletion

Remove files from social.plus storage when they’re no longer needed. Deletion is permanent and cannot be undone.
Permanent Action: File deletion cannot be undone. Ensure you have proper confirmation flows in your application before allowing users to delete files.
let fileRepository = AmityFileRepository(client: client)

do {
    let isDeleted = try await fileRepository.deleteFile(fileId: "<file-id>")
} catch {
    // Handle error here
}

Next Steps