private async void UploadMultiplePhotosToWall(object sender, EventArgs e) { var photo = GetPhoto(); var request1 = VKApi.UploadWallPhotoRequest(new VKUploadImage(photo, VKImageParameters.JpgImage(0.9f)), 0, OwnerId); var request2 = VKApi.UploadWallPhotoRequest(new VKUploadImage(photo, VKImageParameters.JpgImage(0.5f)), 0, OwnerId); var request3 = VKApi.UploadWallPhotoRequest(new VKUploadImage(photo, VKImageParameters.JpgImage(0.1f)), 0, OwnerId); var request4 = VKApi.UploadWallPhotoRequest(new VKUploadImage(photo, VKImageParameters.PngImage()), 0, OwnerId); var batch = new VKBatchRequest(request1, request2, request3, request4); var responses = await batch.ExecuteAsync(); try { RecycleBitmap(photo); var resp = responses.Select(r => ((VKPhotoArray)r.ParsedModel) [0]); var attachments = new VKAttachments(); attachments.AddRange(resp); MakePost("I just uploaded multiple files from the VK Xamarin.Android SDK!", attachments); } catch (VKException ex) { ShowError(ex.Error); } }
private async void UploadSeveralWallPhotos() { var batch = new VKBatchRequest(new [] { VKApi.UploadWallPhotoRequest(UIImage.FromBundle("apple"), VKImageParameters.PngImage(), 0, OwnerId), VKApi.UploadWallPhotoRequest(UIImage.FromBundle("apple"), VKImageParameters.PngImage(), 0, OwnerId), VKApi.UploadWallPhotoRequest(UIImage.FromBundle("apple"), VKImageParameters.PngImage(), 0, OwnerId), VKApi.UploadWallPhotoRequest(UIImage.FromBundle("apple"), VKImageParameters.PngImage(), 0, OwnerId) }); try { // upload var responses = await batch.ExecuteAsync(); Console.WriteLine("Photos: " + string.Concat(responses.Select(r => r.Json))); // create attachments var attachments = new List <string> (); foreach (var response in responses) { var photoInfo = ((VKPhotoArray)response.ParsedModel).ObjectAtIndex <VKPhoto> (0); var attachment = string.Format("photo{0}_{1}", photoInfo.owner_id, photoInfo.id); attachments.Add(attachment); } // post photos var post = VKApi.Wall.Post(new NSMutableDictionary <NSString, NSObject> { { VKApiConst.Attachments, (NSString)string.Join(",", attachments) }, { VKApiConst.OwnerId, (NSNumber)OwnerId } }); var postResponse = await post.ExecuteAsync(); Console.WriteLine("Result: " + postResponse.Json); // open link var postId = ((NSDictionary)postResponse.Json) ["post_id"]; UIApplication.SharedApplication.OpenUrl(new NSUrl(string.Format("http://vk.com/wall{0}_{1}", OwnerId, postId))); } catch (VKException ex) { Console.WriteLine("Error: " + ex.Error); } }