-1

My view I want to check file if it bigger than 500 kb give for example alert()

<img src="@Model.Value" width="95" height="80" id="down-load" data-id="@Model.Key" data upload="@Url.Action("AddPreview", "Images")" />

(function ($) {
$("[data-id]").each(function () {
    var $this = $(this);
    $($this).upload({
        name: 'attachments',
        action: $this.data("upload"),
        enctype: 'multipart/form-data',
        params: {},
        autoSubmit: true,
        onSubmit: function () { },
        onSelect: function () {
         var size = $('#down-load')[0].files[0].size;//do not work

        },
        onComplete: function (e) {
            if (e.charAt(0) != '[') {
                $.fn.showUserActionNotification(e, true);
                return;
            }

            var data = JSON.parse(e);
            if (data[0].Error) {
                $.fn.showUserActionNotification(data[0].Error, true);
            }
            else if (data[0].Preview) {
                $this.attr("src", data[0].Preview);
            }
        }
    });

    $this.parent().find("input").css("cursor", "pointer");
});
})(jQuery);

I want to get size on function onSelect to check it on big Is any body can help me?

Hackerman
  • 12,139
  • 2
  • 34
  • 45
user246340
  • 45
  • 1
  • 7

1 Answers1

0

I have done function

var imageSize = function (e) {
return $.map(e.files, function (file) {
    var name = file.name;
    var size = file.size;

    if (size > 512000) {
        var alert = $(".valid-size-goods").text(name + ": " + (size / 1024).toFixed(2) + " kb");
        alert.dialog({
            title: alert.attr("dlgTitle"),
            modal: true,
            resizable: false,
            buttons: [{ text: alert.attr("btn"), click: function () { $(this).dialog("close"); } }]
        }); return false;
    }
    return true;
});

};

and put it to onSelect:imageSize(e)

user246340
  • 45
  • 1
  • 7