ma11hew28
ma11hew28

Reputation: 126557

Should I save UIImage to file before upload?

I am implementing a photo uploader in Swift.

After getting a UIImage from a UIImagePickerController, I will resize the image, perhaps to be less than 100 KB.

Then, I will convert the UIImage to data using UIImageJPEGRepresentation().

Should I then directly upload the resulting NSData in-memory?

Or, for memory purposes, should I first store the NSData to a file and then upload the file? Would doing that save memory?

Upvotes: 1

Views: 329

Answers (1)

James Webster
James Webster

Reputation: 32076

Chances are, that even if you save the file to disk and then attempt to upload that file, it's going to have to be loaded back into RAM to upload it. I see no benefit to memory by saving to disk first.

However I do like the idea of saving the file to disk as a backup incase the upload fails/the user closes the app; you can offer them the chance to retry the upload.

Upvotes: 2

Related Questions