I am trying to upload a file to the server using www and wwwForm from the client Side using this code :
WWW localFile = new WWW("file://"+ FilePath);
yield return localFile;
WWWForm postForm = new WWWForm();
postForm.AddField("frameCount", Time.frameCount.ToString());
postForm.AddBinaryData("file", localFile.bytes, "filename.obj");
WWW upload = new WWW(uploadUrl, postForm);
yield return upload;
if (upload.error == null)
{
Debug.Log(upload.text);
}
else
{
Debug.Log("Error during upload: " + upload.error);
}
Calling the ASP.net Service Upload File :
public async Task<HttpResponseMessage> UploadFileAsync()
{
try
{
var provider = new MultipartMemoryStreamProvider();
await Request.Content.ReadAsMultipartAsync(provider);
foreach (var file in provider.Contents)
{
var dataStream = await file.ReadAsStreamAsync();
Stream fileStream = File.Create("D:\\filename.obj");
dataStream.CopyTo(fileStream);
fileStream.Close();
dataStream.Close();
var response = Request.CreateResponse(HttpStatusCode.OK);
response.Content = new StringContent("Successful upload", Encoding.UTF8, "text/plain");
response.Content.Headers.ContentType = new MediaTypeWithQualityHeaderValue(@"text/html");
return response;
}
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "No File Uploaded");
}
catch (Exception e)
{
return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e.Message);
}
}
and I am getting ( 500 Internal Server Error)?
the service was running Perfectly, but something wrong Happen, I get 500 Internal Server Error
So what is the Wrong with That?
Thanks in Advance
What I have tried:
The Service was running Perfectly, i tried to increase the maximumFileSize ,
also increasing the request length didn't solve the Issue