Storage downloading costs too much for Firestore app in Swift 4

General Tech Bugs & Fixes 2 years ago

0 2 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on Bugs & Fixes related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (2)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago

 

So the way my app is working is kind of like instagram. A user can upload a photo, and whenever someone loads the app it downloads each picture that was uploaded from the firebase.

I understand that I need to buy f="https://forum.tuteehub.com/tag/space">space or change my plan, but I didn't do that much and I'm wasting 1.7gb from a user in like an hour. Each photo costs like 17mb to upload and download.

I am not sure what I can do to lessen my downloading here.

The way I download from firestore is like this from the f:

// Create a reference to the file you want to download
let islandRef = storageRef.child("f="https://forum.tuteehub.com/tag/image">images/island.jpg")

// Download in memory with a maximum allowed size of 1MB (1 * 1024 * 1024 bytes)
islandRef.getData(maxSize: 1 * 10240 * 10240) { data, error in
  if let error = error {
// Uh-oh, an error occurred!
  } else {
// Data for "f="https://forum.tuteehub.com/tag/image">images/island.jpg" is returned
let f="https://forum.tuteehub.com/tag/image">image = UIImage(data: data!)
  }
}

And each time it loads a photo into a collectionviewcontroller. Which means it is like 17mb for each photo which is a lot. Any suggestions? Thanks

profilepic.png
manpreet 2 years ago

So this is where you want to make a decision about the level of quality for the photos that you upload to firebase. I can assure you that instagram and any other social media platform only store versions of your pictures that are compressed and optimized for size.

You can easily compress your image by doing something like this

let data = imageToUpload.jpegData(compressionQuality: 0.3)

you would then upload that new compressed version of the image to firebase and dramatically improve your storage efficiency.


0 views   0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.