コード例 #1
0
        internal MessageResponse ProcessHttpRequest(InputFileProperties inputFile)
        {
            try
            {
                if (inputFile == null)
                {
                    return(MessageResponse.error("File Not Found"));
                }

                var inputContent = GetInputFileContentAndLogRequest(inputFile);

                var sb = _psTool.ProcessDataFile(inputContent);

                var errorList = _psTool.GetErrors();
                if (errorList.Any())
                {
                    return(MessageResponse.error(errorList));
                }

                var encryptedData = AESHelper.EncryptAES(sb.ToString(), _configuration["AESKeyBLOB"]);
                return(MessageResponse.ok(encryptedData));
            }
            catch (Exception e)
            {
                Logger.Error(e);
                return(MessageResponse.error(e.Message));
            }
        }
コード例 #2
0
        // request nay la send từ postman, qua hàm này request.Content.ReadAsMultipartAsync
        // nó sẽ lầy tên file từ body truyền trên postman
        // System.net.http ko xa2i tre6n .netcore
        // Doc them phan Upload large files with streaming
        // https://docs.microsoft.com/en-us/aspnet/core/mvc/models/file-uploads?view=aspnetcore-3.0
        internal MessageResponse ProcessHttpRequest(MasterConversionRequest request)
        {
            try
            {
                // coi them vd cho .net framework
                // https://stackoverflow.com/questions/14937926/file-name-from-httprequestmessage-content

                //if (!request.Content.IsMimeMultipartContent())
                //    return MessageResponse.info("Invalid media type - multipart");
                //var provider = new MultipartFormDataMemoryStreamProvider();
                //await request.Content.ReadAsMultipartAsync(provider);
                //var inputContent = GetInputFileContentAndLogRequest(provider);
                if (request is null || request.FileData.Length == 0) //TODO length > maximum length
                {
                    return(MessageResponse.error("Bad request. File not found!"));
                }

                var inputContent = GetInputFileContentAndLogRequest(request);

                var sb = _psTool.ProcessDataFile(inputContent);

                var errorList = _psTool.GetErrors();
                if (errorList.Any())
                {
                    return(MessageResponse.error(errorList));
                }

                var encryptedData = AESHelper.EncryptAES(sb, AzureKeyVaultProvider.AESKeyBLOB);
                return(MessageResponse.ok(encryptedData));
            }
            catch (Exception e)
            {
                _logger.Error(e.Message);
                return(MessageResponse.error(e.Message));
            }
        }