1

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?

ma11hew28
  • 121,420
  • 116
  • 450
  • 651
  • "should I first store the NSData to a file and then upload the file" How would you do that? – matt May 07 '15 at 13:46
  • you cannot upload a file from a persistent container, you need to load it into the memory first... you need to save it, if you want to keep it for any future session; if you don't need it why would you save that? – holex May 07 '15 at 13:55

1 Answers1

2

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.

James Webster
  • 31,873
  • 11
  • 70
  • 114