Skip to content

Instantly share code, notes, and snippets.

@wayne-o
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wayne-o/21b748322ebcb7037fdc to your computer and use it in GitHub Desktop.
Save wayne-o/21b748322ebcb7037fdc to your computer and use it in GitHub Desktop.
public MemoryStream ZipStream(MemoryStream input){
UIImage img = input.ToUIImage ();
img = img.Scale (new System.Drawing.SizeF (((img.Size.Width / 100) * 40), ((img.Size.Height / 100) * 40)), 0);
var compressed = img.AsJPEG(0.7f);
var minput = compressed.AsStream ();
MemoryStream zip = new MemoryStream ();
GZipStream zipper = new GZipStream (zip, CompressionMode.Compress);
minput.CopyTo(zipper);
zipper.Flush();
zip.Position = 0;
zip.Seek (0, SeekOrigin.Begin);
return zip;
}
//data is the raw byte array of the image/file being sent
var compressed = ZipStream(new MemoryStream (data));
//we use servicestack but this could be HttpClient - there really is no difference in this context
var client = new ServiceStack.JsonServiceClient (Settings.ApiUrl);
string uploadString = Settings.ApiUrl + "/api/photobatch/?id={0}&latitude={1}&longitude={2}&phonenumber={3}&dealersemail={4}&usersemail={5}&SecondaryEmail={6}";
uploadString = uploadString.With (item.Id, item.Lat, item.Lng, Settings.PhoneNumber, Settings.DealerEmail, Settings.Email, Settings.SecondaryEmail);
client.PostFile<dynamic> (uploadString, compressed, "{0}.gz".With (item.Id), "application/x-gzip");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment