IOS_Boss/IOS_study/Manager/StorageManager.swift
2025-07-27 12:33:06 +08:00

30 lines
655 B
Swift

//
// StorageManager.swift
// IOS_study
//
// Created by CC-star on 2025/7/15.
//
import UIKit
import LeanCloud
final class StorageManager {
static let shared = StorageManager()
private init() { }
func saveImage(_ image: UIImage) async throws -> String {
if let data = image.heicData() {
if Double(data.count) / (1024 * 1024) >= 4 {//4MB
throw UserError.imageTooBig
}
let file = LCFile(payload: .data(data: data))
file.mimeType = "image/heic"
return try await file.save()
} else {
throw UserError.imageToheicDataError
}
}
}