Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am trying to upload a file to the server using www and wwwForm from the client Side using this code :

C#
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 :

C#
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();
                    // use the data stream to persist the data to the server (file system etc)
                    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
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900