NoWar
NoWar

Reputation: 37633

fineUploader error handling

I need to implement a server error during uploading. Here is my code:

 $(document).ready(function () {
    $("#@clientId").fineUploader({
        request: {
            endpoint: '@(Url.Content("~/Admin/Download/AsyncUpload"))'
        },
        template: "@(clientId)-qq-template",
        multiple: false
    }).on("complete", function (event, id, name, responseJSON, xhr) {
        $("#@(clientId + "downloadurl")").html("<a href='" + responseJSON.downloadUrl + "'>@T("Admin.Download.DownloadUploadedFile")</a>");
        $("#@(clientId + "value") input").val(responseJSON.downloadId);
        $("#@(clientId + "remove")").show();
    });
});

The manual on handling errors I have found doesn't help.

Any clue?

Upvotes: 2

Views: 938

Answers (1)

dbeg
dbeg

Reputation: 153

A Fine Uploader server can return a number of response values. To return a server error message, you can simply return a response success value of false (which will trigger an error callback) and populate an error value with whatever messaging you desire:

{
    "success": false,
    "error": "bad filesize"
}

To then do something meaningful with this response, simply leverage the onError callback:

.on("error", function(event, id, name, reason) {
    alert(qq.format("Error on file {} (id = {}). Reason: {}", name, id, reason));
})

Upvotes: 2

Related Questions