0

I am uploading a large file using MVC.I am able to upload a large file but after chunking, merging and deleting not seen any successful message. Here is my code.

Here I clicked upload button after loading gif animated

$('#btnUpload').click(function () {
    var url = '@Url.Action("PostMethod", "Home")';
    $("#divLoading").show();
    UploadFile($('#uploadFile')[0].files);
    $.post(url, null,
        function (data) {
            //  $("#PID")[0].innerHTML = data;
            $("#divLoading").hide();
            //alert("completed");
        });
    }
)

function UploadFileChunk(Chunk, FileName)
{
    var FD = new FormData();
    FD.append('file', Chunk, FileName);
    $.ajax({
        type: "POST",
        url: 'http://localhost:xxxx/Home/UploadFile/',
        contentType: false,
        processData: false,
        data: FD
    });     
}

function UploadFile(TargetFile)
{      
}

Below you can see Home controller.cs file

[HttpPost]
public HttpResponseMessage UploadFile()
{
    try
    {
        if (System.IO.File.Exists(path))
            System.IO.File.Delete(path);
        using (var fileStream = System.IO.File.Create(path))
        {
            stream.CopyTo(fileStream);
        }
        // Once the file part is saved, see if we have enough to merge it
        Shared.Utils UT = new Shared.Utils();
        UT.MergeFile(path);
    }
    catch (IOException ex)
    {
        // handle
    }   

    return new HttpResponseMessage()
    {
        StatusCode = System.Net.HttpStatusCode.OK,
        Content = new StringContent("File uploaded.")
    };
}

Kindly let me know where should I add completed message.

FortyTwo
  • 2,414
  • 3
  • 22
  • 33
Pooja Jadhav
  • 33
  • 1
  • 1
  • 8

1 Answers1

0

In your ajax call:

$.ajax({
    type: "POST",
    url: 'http://localhost:xxxx/Home/UploadFile/',
    contentType: false,
    processData: false,
    data: FD,
    statusCode: {
          200: function(data) {
               // status OK, do something
          }
    }
});     

Anyway, you could return Json objects too and simply process success/error results. Like in this example: Jquery Ajax, return success/error from mvc.net controller

Henrique Forlani
  • 1,325
  • 9
  • 22
  • Thanks @Forlani, i tried the said solution but it goes in loop i need to close the browser. I want a successful message after the chunks are uploaded, files is merged and then the chunks are deleted. The merge code runs on the server. As the merge and delete is done on server, can we send a message from server to client that the files are merged. then we can show message to end user files are uploaded – Pooja Jadhav Jul 15 '17 at 19:59