Last active
August 29, 2015 14:08
-
-
Save wayne-o/21b748322ebcb7037fdc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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