如何在jquery uploadFile方法

时间:2017-10-20 11:22:24

标签: javascript ajax jquery-upload-file-plugin

这是上传js代码

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();
    }
});

},

和保存媒体在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;
}

常见的cs

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

问题是我想在开始上传之前获得媒体类型如果mediatype = 0给出错误但我无法达到结果.CommonGenericObject.MediaType为什么?任何方式得到它?在开始上传之前我需要使用哪个函数来给出错误?

1 个答案:

答案 0 :(得分:0)

我明白了

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