コード例 #1
0
        public async Task <List <HatoAttachment> > UploadAndSaveAttachments(MailgunEmailRaw email)
        {
            var atts = new List <HatoAttachment>();

            foreach (var att in email.Attachments)
            {
                var id         = Ulid.NewUlid();
                var fileStream = await recv.GetAttachment(att.Url);

                var url = await oss.PutAttachment(id, att.Name, fileStream, att.Size, att.ContentType);

                var attachment = new HatoAttachment()
                {
                    AttachmentId = id,
                    Filename     = att.Name,
                    Url          = url,
                    ContentType  = att.ContentType,
                    Size         = att.Size,
                    IsAvailable  = true
                };
                atts.Add(attachment);
            }
            await this.db.AddAttachmentEntries(atts);

            return(atts);
        }
コード例 #2
0
        public async Task <IActionResult> UploadAttachment(
            [FromQuery] string filename
            )
        {
            var _contentLength = Request.ContentLength;

            if (_contentLength == null)
            {
                return(StatusCode(StatusCodes.Status411LengthRequired));
            }
            if (_contentLength > MaxAllowedUploadSize)
            {
                return(StatusCode(StatusCodes.Status413PayloadTooLarge));
            }
            long contentLength = _contentLength.Value;

            var contentType = Request.ContentType;

            if (contentType == null)
            {
                contentType = MimeTypes.GetMimeType(filename);
            }

            var  fileStream = Request.Body;
            Ulid id         = Ulid.NewUlid();
            var  path       = await this.oss.PutAttachment(id, filename, fileStream, contentLength, contentType);

            var att = new HatoAttachment()
            {
                AttachmentId = id,
                Filename     = filename,
                Url          = path,
                ContentType  = contentType,
                Size         = contentLength,
                IsAvailable  = true
            };

            await this.db.AddAttachmentEntry(att);

            return(Created(path, att));
        }