I have been trying to upload a StorageFile (mostly image files) to a PHP File so that it can save into the server.

ViewModel.cs

public async Task<bool> uploadFile(StorageFile file) { try { using (HttpMultipartFormDataContent form = new HttpMultipartFormDataContent()) { using (IInputStream fileStream = await file.OpenSequentialReadAsync()) { HttpStreamContent streamContent = new HttpStreamContent(fileStream); form.Add(streamContent, "file", file.Name); using (HttpClient client = new HttpClient()) { using (HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, new Uri("localhost/uploadFile.php"))) { request.Content = form; HttpResponseMessage response = await client.SendRequestAsync(request); Debug.WriteLine("

Request: " + request.ToString()); Debug.WriteLine("



Response: " + response.ToString()); } } } } return true; } catch (Exception e) { Debug.WriteLine(e.Message); return false; } }

uploadFile.php

<?php $uploaddir = 'uploads/'; $uploadedFile = $uploaddir . basename($_FILES['file']['name']); if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadedFile)){ echo 'File upload success!'; } else { echo 'Possible file upload attack!'; } ?>

The problem is when I try to upload a file, it threw me an error The object has been closed. (Exception from HRESULT: 0X80000013) and Exception thrown: 'System.ObjectDisposedException' in mscorlib.ni.dll .. I don't understand, I do the file uploading inside the using statement, how can it is disposed? Am I doing something wrong?

The debug shows me this