protected override void OnActivityResult(int requestCode, Result resultCode, Intent intent) { try { base.OnActivityResult(requestCode, resultCode, intent); if (requestCode == 0) { if (resultCode == Result.Ok) { Android.Net.Uri uri = intent.Data; //intent variable has a Field named Data which is the complete URI for the file. //Android.Net.Uri uris = Android.Net.Uri.FromParts(intent.Data.Scheme, intent.Data.SchemeSpecificPart, intent.Data.Fragment); //System.IO.Stream input = ContentResolver.OpenInputStream(intent.Data); //FileStream fileStream = input as FileStream; //if (fileStream != null) //{ // //It was really a file stream, get your information here // Toast.MakeText(this, "Stream is still null", ToastLength.Short).Show(); //} //else //{ // //The stream was not a file stream, do whatever is required in that case // Toast.MakeText(this, "Stream is not a filestream", ToastLength.Short).Show(); //} if (GetRealPathFromURI(uri) == null) { Toast.MakeText(this, "Path is still null", ToastLength.Short).Show(); } Dictionary <string, Permission> users = new Dictionary <string, Permission>(); users.Add(this.userController.CurrentUser.UserName, Permission.Owner); Toast.MakeText(this, GetRealPathFromURI(uri), ToastLength.Short).Show(); byte[] file = System.IO.File.ReadAllBytes(GetRealPathFromURI(uri)); File uploadFile = new File(); uploadFile.GUID = "_" + uploadFile; Toast.MakeText(this, "Adding GUID", ToastLength.Short).Show(); uploadFile.Name = "_NewFile"; uploadFile.Users = users; uploadFile.Extension = "jpg"; uploadFile.Content = file; Toast.MakeText(this, "Set File", ToastLength.Short).Show(); FileController controller = new FileController(); Toast.MakeText(this, "Before Upload", ToastLength.Short).Show(); controller.UploadFile(uploadFile); } } } catch (Exception e) { Toast.MakeText(this, e.ToString(), ToastLength.Long).Show(); string path = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop); Note testNote = new Note(); //owner title content guid testNote.Owner = this.userController.CurrentUser.UserName; testNote.GUID = "5"; testNote.Title = "Error Note"; testNote.Content = e.ToString(); System.IO.File.WriteAllText(path, e.ToString()); NoteController controller = new NoteController(); controller.CreateNote(testNote, this.userController.CurrentUser.UserName); } }
public void UploadFile(File file) { string json = JsonConvert.SerializeObject(file); PassToServer("file", "UploadFile", json: json); }