Beispiel #1
0
        public override FileUploadResult ProcessUpload(HttpContext context)
        {
            if (!SecurityContext.IsAuthenticated)
            {
                throw new HttpException(403, "Access denied.");
            }

            var result = new FileUploadResult {
                Success = false
            };

            try
            {
                if (FileToUpload.HasFilesToUpload(context))
                {
                    var file        = new FileToUpload(context);
                    var maxFileSize = MaxFileSizeInMegabytes * 1024 * 1024;

                    if (string.IsNullOrEmpty(file.FileName))
                    {
                        throw new ArgumentException("Empty file name");
                    }

                    if (maxFileSize < file.ContentLength)
                    {
                        throw new Exception(CalendarJSResource.calendarEventAttachments_fileSizeError);
                    }

                    var fileName = System.IO.Path.GetFileName(file.FileName);

                    var document = new File
                    {
                        Title           = fileName,
                        FolderID        = AttachmentEngine.GetTmpFolderId(),
                        ContentLength   = file.ContentLength,
                        ThumbnailStatus = Thumbnail.NotRequired
                    };

                    document = AttachmentEngine.SaveFile(document, file.InputStream);

                    result.Data = new
                    {
                        id          = document.ID.ToString(),
                        title       = document.Title,
                        size        = document.ContentLength,
                        contentType = file.FileContentType,
                        fileUrl     = FileShareLink.GetLink(document) + "&tmp=true"
                    };

                    result.Success = true;
                }
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.Message = ex.Message;
            }

            return(result);
        }
Beispiel #2
0
        public void Init()
        {
            _context = new AddonContext
            {
                DefaultSortOrder      = 80,
                DisabledIconFileName  = "disabledlogo.png",
                IconFileName          = "logo.png",
                LargeIconFileName     = "product_logolarge.svg",
                SubscriptionManager   = new CalendarSubscriptionManager(),
                SpaceUsageStatManager = new CalendarSpaceUsageStatManager(),
            };

            AttachmentEngine.RegisterFileSecurityProvider();
        }