Storage File(主にイメージファイル)をPHPファイルにアップロードして、サーバーに保存できるようにしています。問題は、私はファイルをアップロードしようとすると、それは私にエラーThe object has been closed. (Exception from HRESULT: 0X80000013)
を投げ、Exception thrown: 'System.ObjectDisposedException' in mscorlib.ni.dll
あるStorageFileをPHPファイルにアップロード
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("\nRequest: " + request.ToString());
Debug.WriteLine("\n\nResponse: " + 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!';
}
?>
..私は理解していません私はファイルusing
の中にアップロードします、どのように処分することができますか?私は何か間違っているのですか?
デバッグが私にこの
要求を示しています。方法:POST、RequestUri: 'http://localhost/uploadFile.php' を、内容:Windows.Web.Http.HttpMultipartFormDataContent、TransportInformation:ServerCertificate: ''、ServerCertificateErrorSeverity:なし、ServerCertificateErrors: {Content-Length:27749、Content-Type:multipart/form-data; {}、ServerIntermediateCertificates:{}、ヘッダー:{Accept-Encoding:gzip、deflate}境界:9955f08b-e82d-428b-82e1-3197e5011ccd
レスポンス:StatusCode:200、ReasonPhrase: 'OK'、バージョン:2、内容:Windows.Web.Http.HttpStreamContent、ヘッダー:{Connection:Keep-Alive 、サーバー:Apache/2.4.18(Ubuntu)、キープアライブ:タイムアウト= 5、最大= 100、日付:Sun、2016年11月6日04:02:40 GMT} {Content-Length:28、Content-Type:text/html; charset = UTF-8}