Пример #1
0
        public async Task <IActionResult> Upload()
        {
            if (!Request.IsMultipartContentType())
            {
                return(BadRequest($"Expected a multipart request, but got {Request.ContentType}"));
            }

            // Bind form data to a model
            var logUploadData = await GetModelAsync <LogUploadData>();

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var resourcePath = TempFileService.GetFilePath(logUploadData.LogFile);

            var checkRun = await _checkRunSubmissionService.SubmitAsync(
                RepositoryOwner,
                RepositoryName,
                logUploadData.CommitSha,
                resourcePath,
                logUploadData.PullRequestNumber);

            _telemetryService.CreateCheckRun(RepositoryOwner, RepositoryName);

            return(Json(checkRun));
        }
Пример #2
0
 public ReplaceImageCommandHandler(DatabaseContext context, TempFileService tempFileService, IApplicationEventDispatcher dispatcher, IDistributedCache distributedCache)
 {
     _context          = context;
     _tempFileService  = tempFileService;
     _dispatcher       = dispatcher;
     _distributedCache = distributedCache;
 }
Пример #3
0
 public ImageProcessor(DatabaseContext context, IDetailsApi detailsApi, TempFileService tempFileService, IBackgroundJobClient backgroundJobClient, IApplicationEventDispatcher dispatcher)
 {
     _context             = context;
     _detailsApi          = detailsApi;
     _tempFileService     = tempFileService;
     _backgroundJobClient = backgroundJobClient;
     _dispatcher          = dispatcher;
 }
 public Task <ActionResult> DownloadTempFile(string key) => TempFileService.Download(key);
Пример #5
0
 public Task <ActionResult> DownloadTempFile(string key)
 {
     return(TempFileService.Download(key));
 }
        protected async Task <KeyValueAccumulator> BuildMultiPartFormAccumulator <TModel>() where TModel : class, new()
        {
            var httpContextRequest = HttpContext.Request;

            // Used to accumulate all the form url encoded key value pairs in the request
            var formAccumulator = new KeyValueAccumulator();

            var boundary = Request.GetBoundary(_defaultFormOptions);
            var reader   = new MultipartReader(boundary, httpContextRequest.Body);

            Logger.LogDebug("Reading next section");

            var section = await reader.ReadNextSectionAsync();

            while (section != null)
            {
                var hasContentDispositionHeader =
                    ContentDispositionHeaderValue.TryParse(section.ContentDisposition, out var contentDisposition);

                if (hasContentDispositionHeader)
                {
                    Logger.LogDebug("Content Disposition Header: {0}", section.ContentDisposition);

                    if (contentDisposition.IsFileContentDisposition())
                    {
                        var fileName = contentDisposition.FileName.Value;

                        var formFileNames = FormFileAttributeHelper.GetFormFileNames(typeof(TModel));
                        if (!formFileNames.Contains(contentDisposition.Name.Value))
                        {
                            Logger.LogWarning($"Unknown file '{contentDisposition.Name.Value}' with fileName: '{fileName}' is being ignored.");
                            // Drains any remaining section body that has not been consumed and
                            // reads the headers for the next section.
                            section = await reader.ReadNextSectionAsync();

                            continue;
                        }

                        formAccumulator.Append(contentDisposition.Name.Value, fileName);

                        var path = await TempFileService.CreateFromStreamAsync(fileName, section.Body);

                        Logger.LogInformation($"Copied the uploaded file '{fileName}' to path: '{path}'");
                    }
                    else if (contentDisposition.IsFormDataContentDisposition())
                    {
                        // Content-Disposition: form-data; name="key"

                        // Do not limit the key name length here because the
                        // multipart headers length limit is already in effect.
                        var key = HeaderUtilities.RemoveQuotes(contentDisposition.Name);

                        Logger.LogDebug("Retrieving value for {0}", key);

                        var encoding     = section.GetEncoding();
                        var streamReader = new StreamReader(
                            section.Body,
                            encoding,
                            detectEncodingFromByteOrderMarks: true,
                            bufferSize: 1024,
                            leaveOpen: true);
                        using (streamReader)
                        {
                            // The value length limit is enforced by MultipartBodyLengthLimit
                            var value = await streamReader.ReadToEndAsync();

                            if (string.Equals(value, "undefined", StringComparison.OrdinalIgnoreCase))
                            {
                                value = string.Empty;
                            }

                            formAccumulator.Append(key.Value, value);

                            if (formAccumulator.ValueCount > _defaultFormOptions.ValueCountLimit)
                            {
                                throw new InvalidDataException(
                                          $"Form key count limit {_defaultFormOptions.ValueCountLimit} exceeded.");
                            }
                        }
                    }
                }

                // Drains any remaining section body that has not been consumed and
                // reads the headers for the next section.
                section = await reader.ReadNextSectionAsync();
            }

            return(formAccumulator);
        }
 protected SetImageCommandHandler(FolderOptions folderOptions, TempFileService tempFileService, IImageService imageService)
 {
     _tempFileService = tempFileService;
     ImageService     = imageService;
     _imageFolder     = folderOptions.Images;
 }
Пример #8
0
 public SetLogoImageCommandHandler(FolderOptions folderOptions, TempFileService tempFileService, IImageService imageService)
     : base(folderOptions, tempFileService, imageService)
 {
 }
 public CreateSnapshotCommandHandler(TempFileService tempFileService)
 {
     _tempFileService = tempFileService;
 }