コード例 #1
0
        public MediaFile Execute(UploadFileRequest request)
        {
            var maxLength = CmsConfiguration.Storage.MaximumFileNameLength > 0 ? CmsConfiguration.Storage.MaximumFileNameLength : 100;

            var fileName = request.FileName;

            if (fileName.Length > maxLength)
            {
                fileName = string.Concat(Path.GetFileNameWithoutExtension(fileName.Substring(0, maxLength)), Path.GetExtension(fileName));
            }

            if (request.Type == MediaType.File || request.Type == MediaType.Audio || request.Type == MediaType.Video)
            {
                var media = MediaFileService.UploadFile(request.Type, request.RootFolderId, fileName, request.FileLength, request.FileStream);

                Events.MediaManagerEvents.Instance.OnMediaFileUploaded(media);

                return(media);
            }

            if (request.Type == MediaType.Image)
            {
                var media = MediaImageService.UploadImage(request.RootFolderId, fileName, request.FileLength, request.FileStream, request.ReuploadMediaId);

                Events.MediaManagerEvents.Instance.OnMediaFileUploaded(media);

                return(media);
            }

            throw new CmsException(string.Format("A given media type {0} is not supported to upload.", request.Type));
        }
コード例 #2
0
        public MediaFile Execute(UploadFileRequest request)
        {
            if (request.Type == MediaType.File || request.Type == MediaType.Audio || request.Type == MediaType.Video)
            {
                var media = MediaFileService.UploadFile(request.Type, request.RootFolderId, request.FileName, request.FileLength, request.FileStream);

                Events.MediaManagerEvents.Instance.OnMediaFileUploaded(media);

                return(media);
            }

            if (request.Type == MediaType.Image)
            {
                var media = MediaImageService.UploadImage(request.RootFolderId, request.FileName, request.FileLength, request.FileStream);

                Events.MediaManagerEvents.Instance.OnMediaFileUploaded(media);

                return(media);
            }

            throw new CmsException(string.Format("A given media type {0} is not supported to upload.", request.Type));
        }