Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
299 views
in Technique[技术] by (71.8m points)

ios - Uploading an Image instead of an UIImage to Firestore

Using Swift 5.0 / SwiftUI 2.0

One method available when uploading an UIImage to Firestore is jpegData(compressionQuality: Double) which essentially makes the whole process of fetching the saved image a lot faster.

Is there any equivalent for Image yet or any other viable workarounds or its as simple as either UIImage or poor UX


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
struct ContentView: View {
    
    //Here
    @State var uiImage: UIImage?
    
    var body: some View {
        VStack {
            if uiImage != nil {
                Image(uiImage: uiImage!)
            }
            
            
            Button(action: {
                downloadImage()
            }, label: {
                Text("Download image")
            })
        }
        
    }

    func downloadImage() {
        URLSession.shared.dataTask(with:URL(string: "https://upload.wikimedia.org/wikipedia/commons/3/3f/Self-portrait_taken_with_laptop%2C_March%2C_2018.jpg")!) { (data, response, eooror) in
            guard data != nil else { return }
            
            DispatchQueue.main.async {
                self.uiImage = UIImage(data: data!)
            }
    
        }.resume()
    }
    
    //Here
    func getData() {
        var data = uiImage?.jpegData(compressionQuality: 0.5)
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...