30 lines
655 B
Swift
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
|
|
}
|
|
}
|
|
}
|