public FishModels.ExifData GetExifData(Stream s) { FishModels.ExifData e = new FishModels.ExifData(); double[] latArray; double[] longArray; string latRef; string longRef; // Instantiate the reader try { using (ExifReader reader = new ExifReader(s)) { DateTime dt = new DateTime(); reader.GetTagValue(ExifTags.DateTimeOriginal, out dt); if (dt.Date < DateTime.Now.AddYears(-100)) //checking if date is *Loval { reader.GetTagValue(ExifTags.DateTimeDigitized, out dt); } if (dt.Date < DateTime.Now.AddYears(-100)) //checking if date is *Loval { reader.GetTagValue(ExifTags.DateTime, out dt); } e.dateTimeTaken = dt; reader.GetTagValue(ExifTags.Orientation, out e.Orientation); reader.GetTagValue(ExifTags.GPSAltitude, out e.GPSAltitude); reader.GetTagValue(ExifTags.GPSDifferential, out e.GPSDifferential); reader.GetTagValue(ExifTags.GPSImgDirection, out e.GPSImgDirection); reader.GetTagValue(ExifTags.GPSLatitude, out latArray); reader.GetTagValue(ExifTags.GPSLongitude, out longArray); reader.GetTagValue(ExifTags.GPSLongitudeRef, out longRef); reader.GetTagValue(ExifTags.GPSLatitudeRef, out latRef); if (latArray != null && longArray != null) { e.GPSLatitude = ConvertDegreesToDecimalDegrees(latArray, latRef); e.GPSLongitude = ConvertDegreesToDecimalDegrees(longArray, longRef); } } } catch (Exception ex) { //error.logError(ex.Message, ex.Source, ex.StackTrace, "Enter Fish", "DatabaseClass", "saveImage", HttpContext.Current.User.Identity.Name, null); return(e); } return(e); }
public JsonResult AsyncUpload(IEnumerable <HttpPostedFileBase> files) { int count = 0; //string thumbNail; string fishID = ""; string imageUrl = ""; decimal imageLat = 0; decimal imageLong = 0; DateTime imageDateTime = new DateTime(); if (files != null) { foreach (var file in files) { if (file != null && file.ContentLength > 0 && file.ContentLength / 1000 < 4096) { //resize MemoryStream s1 = resizeImage(file, "thumb"); FishModels.AmazonS3Url thumbUrl = UploadToS3(s1, "thumb"); MemoryStream s2 = resizeImage(file, "1000"); FishModels.AmazonS3Url fullSizeUrl = UploadToS3(s2, "1000"); ////get Exif Data Stream s = file.InputStream; FishModels.ExifData e = GetExifData(s); FishModels.FishImage image = new FishModels.FishImage(); FishModels.NewFishInfo newFishInfo = (FishModels.NewFishInfo)Session["NewFishInfo"]; image.FishID = newFishInfo.fishID; image.ExifData = e; image.thumb = thumbUrl; image.fullSize = fullSizeUrl; //get some stuff from first image only if (count == 0) { imageUrl = fullSizeUrl.url; imageLat = image.ExifData.GPSLatitude; imageLong = image.ExifData.GPSLongitude; imageDateTime = image.ExifData.dateTimeTaken; } //save image data to DB dbClass.SaveImage(image); fishID = image.FishID; // get weather data //getWeatherData(imageLat, imageLong, image.ExifData.dateTimeTaken); } //upload to amazon S3 //save S3 key to DB //get exif data //save exif data to DB //start API calls for weather, water level, etc... //file.SaveAs(path); count++; } } var result = new { url = imageUrl, //imageKey = fishID, latitude = imageLat, longitude = imageLong, imageDate = imageDateTime.ToShortDateString(), imageTime = imageDateTime.ToShortTimeString() }; return(Json(result, JsonRequestBehavior.AllowGet)); }