DESCRIPTION: I'm uploading images to a server taken with a phone app using Mvvmcross TakePicture method.
PROBLEM: The original size image in the Gallery of the Phone contains the GPS tags, but the re-scaled one arriving to the server doesn't.
INFO: I've uploaded an image from a webpage to test the server side code an the GPS tag was there.
This is the code where I'm taking the picture and saving it:
_pictureChooserTask.TakePicture(MaxPixelDimension,DefaultJpegQuality,OnPicture,()=>{});
private void OnPicture(Stream stream)
{
var memorystream = new MemoryStream();
stream.CopyToAsync(memorystream);
PictureBytes = memorystream.ToArray();
_fileStore.EnsureFolderExists("Images");
var path = _fileStore.PathCombine("Images", "test.jpg");
_fileStore.WriteFile(path, PictureBytes);
}
This is the upload part:
var result = Mvx.Resolve<IMvxFileStore>().TryReadBinaryFile(imagePath, out imageBytes);
var content = new MultipartFormDataContent();
var fileContent = new ByteArrayContent(imageBytes,0,imageBytes.Count());
var fileName = mediaPartner.GpCode+Guid.NewGuid() + ".jpg";
const string reference = "picture";
fileContent.Headers.ContentType = MediaTypeHeaderValue.Parse("multipart/form-data");
fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
{
FileName = fileName,
Name = reference,
};
content.Add(fileContent);
content.Add(new StringContent(Settings.UserId), "userid");
var backendresp = await client.PostAsync(server + route, content);
QUESTION: Is it possible that my image will lose the meta tags when it is re-scaled and saved or when it is prepared for upload?
The MvvmCross plugin resizes using https://github.com/MvvmCross/MvvmCross/blob/v3.1/Plugins/Cirrious/PictureChooser/Cirrious.MvvmCross.Plugins.PictureChooser.Droid/MvxPictureChooserTask.cs
This code won't preserve jpeg metadata - so if that's important to your app, then you'll need to write and inject your own implementation.