javascriptajaxjquery-upload-file-plugin

How to get return object in jquery uploadFile method


this is upload js code

manageMedia_Uploader = $("#fileuploader").uploadFile({
    url: "/Ajax/JsonProvider?Method=SaveMedia",
    fileName: "Media",
    autoSubmit: false,
    multiple: false,
    maxFileCount: 1,
    acceptFiles: "audio/*,video/*,image/*",
    showStatusAfterError: true,
    dynamicFormData: function () {
        return { MediaFriendlyName: $("#ManageMedia-MediaFriendlyName").val(), MediaID: mediaID }
    },
    afterUploadAll: function (result) {
        console.log("MEDIAID: " + result.CommonGenericObject);
        if (mediaID!=0)
            Management_ManageMedia.GoToMediaManagement();
    },
    onError: function (files, status, errMsg, pd) {
        Management_ManageMedia.GoToMediaManagement();
    },
    onCancel: function (files, pd) {
        Management_ManageMedia.GoToMediaManagement();
    }
});

},

and SaveMedia at ajax.cs

public CommonDto SaveMedia(){
    Common.MediaType mediaType = Common.MediaType.Unknowm;
    CommonDto result = new CommonDto();
     if (fileExtension == ".webm" || fileExtension == ".mkv" || fileExtension == ".flv" || fileExtension == ".vob" || fileExtension == ".ogv" || fileExtension == ".avi" || fileExtension == ".wmv" || fileExtension == ".mp4" || fileExtension == ".mpg" || fileExtension == ".mpeg" || fileExtension == ".flv")
    {
        mediaType = Common.MediaType.Video;
    }
    else if (fileExtension == ".jpg" || fileExtension == ".jpeg" || fileExtension == ".gif" || fileExtension == ".png" || fileExtension == ".gif" || fileExtension == ".bmp")
    {
        mediaType = Common.MediaType.Image;
    }

    if (mediaType == Common.MediaType.Unknowm)
    {
        notification.NotificationMessage = notification.NotificationMessage = LocalizeHelper.GetLanguageResource("aabcc9eb-26f7-4c42-b355-4f23ce9f5d62", "{en: 'Please upload a media as allowed types', tr: 'Lütfen izin verilen türde bir medya yükleyin', ar: 'يرجى تحميل وسائط كأنواع مسموح بها'}", SessionHelper.GetUser<UserDto>().LanguageID, false);
        notification.NotificationType = Common.NotificationType.Warning;
    }
    media.Mediatype=(int)mediaType
    result.CommonGenericObject = media;

    result.CommonNotification = notification;
    return result;
}

common cs

public enum MediaType
    {
     Unknowm = 0,
     Image = 1,
     Video = 2,
     Audio = 3
    }

And the problem is i want to get media type before start upload if mediatype=0 give error but i cant reach result.CommonGenericObject.MediaType why ? any way to get it ? and which function am i need to be use for give error before start uploading?


Solution

  • i get it

    (JSON.parse(result.responses)).CommonGenericObject