0

I'm able to upload an image using ASIHTTPRequest.

Code is something like this.

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    NSData *imageData = UIImageJPEGRepresentation(self.selectedImage.image, 0.5);

    ...
}

Is there anyway I can find out the file size of that "imageData". Basically trying to find out what file size I'm uploading and if there is anyway that I can optimize the file size if it is too large.

Thank you,
Tee

teepusink
  • 27,444
  • 37
  • 107
  • 147

1 Answers1

3

It's pretty easy to find the size: NSData supports the length method:

NSUInteger imageSize = [imageData length];

Optimization options will then depend on what your server supports

Tim Dean
  • 8,253
  • 2
  • 32
  • 59
  • Hey Tim, what do you mean with "Optimization options will then depend on what your server supports"? Is there a way that the iphone side can optimize the data size send over? I notice that when I download a picture from my iphone, it is usually about 2-3MB-ish. Is there a way I can cut that to 0.5 MB? Or is the NSData already an optimized version? – teepusink Aug 30 '11 at 23:59
  • How optimized the image is will likely depend on the format and contents of the image file you pick. NSData will simply represent the file contents as a sequence of bytes - No "extra" optimization will be applied. If you want to do something more you can do things like applying zip compression before sending over the wire, but your server side needs to support that, expect it, and know how do decompress before doing what it needs to. – Tim Dean Aug 31 '11 at 00:09
  • If you're creating a JPEG representation (or PNG) then zip won't by you much. It's already compressed. The only options you have are the quality (0.5) in the JPEG method call or resizing then creating a jpeg or png. – bryanmac Aug 31 '11 at 00:21