Ejemplo n.º 1
0
        public async Task <SendResponseModel> PostFile()
        {
            if (!Request?.ContentType.Contains("multipart/") ?? true)
            {
                throw new BadRequestException("Invalid content.");
            }

            if (Request.ContentLength > 105906176) // 101 MB, give em' 1 extra MB for cushion
            {
                throw new BadRequestException("Max file size is 100 MB.");
            }

            Send send = null;
            await Request.GetSendFileAsync(async (stream, fileName, model) =>
            {
                model.ValidateCreation();
                var userId = _userService.GetProperUserId(User).Value;
                var(madeSend, madeData) = model.ToSend(userId, fileName, _sendService);
                send = madeSend;
                await _sendService.SaveFileSendAsync(send, madeData, model.FileLength.GetValueOrDefault(0));
                await _sendService.UploadFileToExistingSendAsync(stream, send);
            });

            return(new SendResponseModel(send, _globalSettings));
        }