コード例 #1
0
        public ActionResult DownloadAttachment(int attachmentId, bool?needsDownload, int?width, int?height)
        {
            //TODO: security here
            var attContentInfo = SchoolLocator.AttachementService.GetAttachmentContent(attachmentId);

            if (attContentInfo == null)
            {
                Response.StatusCode        = 404;
                Response.StatusDescription = HttpWorkerRequest.GetStatusDescription(Response.StatusCode);
                return(null);
            }
            var attName         = attContentInfo.Attachment.Name;
            var content         = attContentInfo.Content;
            var contentTypeName = MimeHelper.GetContentTypeByName(attName);

            if (MimeHelper.GetTypeByName(attName) == MimeHelper.AttachmenType.Picture && width.HasValue && height.HasValue)
            {
                content = ImageUtils.Scale(content, width.Value, height.Value);
            }
            if (needsDownload.HasValue && !needsDownload.Value)
            {
                Response.AddHeader(CONTENT_DISPOSITION, string.Format(HEADER_FORMAT, attName));
                return(File(content, contentTypeName));
            }
            return(File(content, contentTypeName, attName));
        }
コード例 #2
0
 public static AttachmentViewData Create(AttachmentInfo attachmentInfo, bool isOwner)
 {
     return(new AttachmentViewData
     {
         Id = attachmentInfo.Attachment.Id,
         Name = attachmentInfo.Attachment.Name,
         MimeType = attachmentInfo.Attachment.MimeType,
         Type = (int)MimeHelper.GetTypeByName(attachmentInfo.Attachment.Name),
         Uuid = attachmentInfo.Attachment.Uuid,
         Uploaded = attachmentInfo.Attachment.UploadedDate,
         LastAttached = attachmentInfo.Attachment.LastAttachedDate,
         StiAttachment = attachmentInfo.Attachment.IsStiAttachment,
         ThumbnailUrl = attachmentInfo.DownloadThumbnailUrl,
         Url = attachmentInfo.DownloadDocumentUrl,
         IsTeacherAttachment = attachmentInfo.IsTeacherAttachment,
         IsOwner = isOwner
     });
 }
コード例 #3
0
        public static AttachmentViewData CreateForSysAdmin(string filename, string key)
        {
            var url = new BlobHelper().GetBlobsRelativeAddress("pictureconteiner", key);

            return(new AttachmentViewData
            {
                Id = -1,
                IsOwner = true,
                Name = filename,
                Type = (int)MimeHelper.GetTypeByName(filename),
                IsTeacherAttachment = false,
                LastAttached = DateTime.UtcNow,
                MimeType = MimeHelper.GetContentTypeByName(filename),
                PublicUrl = url,
                StiAttachment = false,
                ThumbnailUrl = null,
                Uploaded = DateTime.UtcNow,
                Url = null,
                Uuid = null
            });
        }
コード例 #4
0
 public bool IsDocument(string fileName)
 {
     return(MimeHelper.GetTypeByName(fileName) == MimeHelper.AttachmenType.Document);
 }
コード例 #5
0
        public ActionResult PublicAttachment(string r, bool?needsDownload, int?width, int?height)
        {
            if (string.IsNullOrWhiteSpace(r))
            {
                Response.StatusCode        = 400;
                Response.StatusDescription = HttpWorkerRequest.GetStatusDescription(Response.StatusCode);
                return(null);
            }

            MasterLocator = ServiceLocatorFactory.CreateMasterSysAdmin();

            Guid districtId;
            int  schoolId;
            Guid userId;
            int  attachmentId;

            if (!AttachmentSecurityTools.TryParseAndVerifyRequestStr(r, out districtId, out schoolId, out userId, out attachmentId))
            {
                Response.StatusCode        = 400;
                Response.StatusDescription = HttpWorkerRequest.GetStatusDescription(Response.StatusCode);
                return(null);
            }

            var user = MasterLocator.UserService.GetById(userId);

            SchoolLocator = ServiceLocatorFactory.CreateSchoolLocator(new SchoolUser
            {
                DistrictRef = districtId,
                SchoolRef   = schoolId,
                UserRef     = user.SchoolUsers.First(x => x.SchoolRef == schoolId).UserRef,
                School      = MasterLocator.SchoolService.GetById(districtId, schoolId),
                User        = new User
                {
                    Login     = string.Empty,
                    LoginInfo = new UserLoginInfo
                    {
                        SisToken        = string.Empty,
                        SisTokenExpires = null
                    },
                    DistrictRef = districtId,
                    District    = MasterLocator.DistrictService.GetByIdOrNull(districtId)
                }
            });

            var attContentInfo = SchoolLocator.AttachementService.GetAttachmentContent(attachmentId);

            if (attContentInfo == null)
            {
                Response.StatusCode        = 404;
                Response.StatusDescription = HttpWorkerRequest.GetStatusDescription(Response.StatusCode);
                return(null);
            }

            var attName         = attContentInfo.Attachment.Name;
            var content         = attContentInfo.Content;
            var contentTypeName = MimeHelper.GetContentTypeByName(attName);

            if (MimeHelper.GetTypeByName(attName) == MimeHelper.AttachmenType.Picture && width.HasValue && height.HasValue)
            {
                content = ImageUtils.Scale(content, width.Value, height.Value);
            }

            if (needsDownload.HasValue && !needsDownload.Value)
            {
                Response.AddHeader(CONTENT_DISPOSITION, string.Format(HEADER_FORMAT, attName));
                return(File(content, contentTypeName));
            }

            return(File(content, contentTypeName, attName));
        }