Exemple #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));
        }
Exemple #2
0
        public T PostWithFile <T>(string url, string fileName, byte[] fileContent, NameValueCollection parameters, HttpMethod method = null)
        {
            var headers  = InitHeaders();
            var fileType = MimeHelper.GetContentTypeByName(fileName);

            return(ChalkableHttpFileLoader.HttpUploadFile(url, fileName, fileContent, fileType
                                                          , ThrowWebException, JsonConvert.DeserializeObject <T>, parameters, headers, method ?? HttpMethod.Post));
        }
Exemple #3
0
        private DocumentUploadResponse UploadFileToCrocodoc(string fileName, byte[] fileContent)
        {
            var nvc = new NameValueCollection {
                { TOKEN, GetToken() }
            };
            var fileType = MimeHelper.GetContentTypeByName(fileName);

            return(ChalkableHttpFileLoader.HttpUploadFile(UrlTools.UrlCombine(GetCrocodocApiUrl(), DOCUMENT_UPLOAD)
                                                          , fileName, fileContent, fileType, HandleUploadException, Deserialize <DocumentUploadResponse>, nvc));
        }
        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
            });
        }
Exemple #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));
        }