publicasync Task<IActionResult> UploadDatabase() { if (!MultipartRequestHelper.IsMultipartContentType(Request.ContentType)) { ModelState.AddModelError("File", $"The request couldn't be processed (Error 1)."); // Log error
return BadRequest(ModelState); }
// Accumulate the form data key-value pairs in the request (formAccumulator). var formAccumulator = new KeyValueAccumulator(); var trustedFileNameForDisplay = string.Empty; var untrustedFileNameForStorage = string.Empty; var streamedFileContent = Array.Empty<byte>();
var boundary = MultipartRequestHelper.GetBoundary( MediaTypeHeaderValue.Parse(Request.ContentType), _defaultFormOptions.MultipartBoundaryLengthLimit); var reader = new MultipartReader(boundary, HttpContext.Request.Body);
var section = await reader.ReadNextSectionAsync();
while (section != null) { var hasContentDispositionHeader = ContentDispositionHeaderValue.TryParse( section.ContentDisposition, outvar contentDisposition);
if (hasContentDispositionHeader) { if (MultipartRequestHelper .HasFileContentDisposition(contentDisposition)) { untrustedFileNameForStorage = contentDisposition.FileName.Value; // Don't trust the file name sent by the client. To display // the file name, HTML-encode the value. trustedFileNameForDisplay = WebUtility.HtmlEncode( contentDisposition.FileName.Value);
if (!ModelState.IsValid) { return BadRequest(ModelState); } } elseif (MultipartRequestHelper .HasFormDataContentDisposition(contentDisposition)) { // Don't limit the key name length because the // multipart headers length limit is already in effect. var key = HeaderUtilities .RemoveQuotes(contentDisposition.Name).Value; var encoding = GetEncoding(section);
if (encoding == null) { ModelState.AddModelError("File", $"The request couldn't be processed (Error 2)."); // Log error
return BadRequest(ModelState); }
using (var streamReader = new StreamReader( section.Body, encoding, detectEncodingFromByteOrderMarks: true, bufferSize: 1024, leaveOpen: true)) { // The value length limit is enforced by // MultipartBodyLengthLimit varvalue = await streamReader.ReadToEndAsync();
if (string.Equals(value, "undefined", StringComparison.OrdinalIgnoreCase)) { value = string.Empty; }
formAccumulator.Append(key, value);
if (formAccumulator.ValueCount > _defaultFormOptions.ValueCountLimit) { // Form key count limit of // _defaultFormOptions.ValueCountLimit // is exceeded. ModelState.AddModelError("File", $"The request couldn't be processed (Error 3)."); // Log error
return BadRequest(ModelState); } } } }
// Drain any remaining section body that hasn't been consumed and // read the headers for the next section. section = await reader.ReadNextSectionAsync(); }
// Bind form data to the model var formData = new FormData(); var formValueProvider = new FormValueProvider( BindingSource.Form, new FormCollection(formAccumulator.GetResults()), CultureInfo.CurrentCulture); var bindingSuccessful = await TryUpdateModelAsync(formData, prefix: "", valueProvider: formValueProvider);
if (!bindingSuccessful) { ModelState.AddModelError("File", "The request couldn't be processed (Error 5)."); // Log error
return BadRequest(ModelState); }
// **WARNING!** // In the following example, the file is saved without // scanning the file's contents. In most production // scenarios, an anti-virus/anti-malware scanner API // is used on the file before making the file available // for download or for use by other systems. // For more information, see the topic that accompanies // this sample app.
ngOnInit() { const obsfrom2 = from('Hello World'); obsfrom2.subscribe(val =>console.log(val), error =>console.log("error"), () =>console.log("complete")) } *** Output **** H e l l o W o r l d complete
//ViewChild returns ElementRef i.e. input HTML Element @ViewChild('nameInput',{static:false, read: ElementRef}) elRef; //ViewChild returns NgModel associated with the nameInput @ViewChild('nameInput',{static:false, read: NgModel}) inRef;
QueryList将viewChildren或contentChildren返回的项存储在列表中。 只要应用程序的状态发生变化,Angular就会更新此列表。它在每次检测到变化时都会这样做。 QueryList还实现了一个可迭代的接口。这意味着您可以使用for(var i of items)对其进行迭代,也可以在template*ngFor=“let i of item”中与ngFor一起使用。 可以通过订阅可观察的更改来观察更改。
<app-card> <header><h1>Angular</h1></header> <content>One framework. Mobile & desktop.</content> <footer><b>Super-powered by Google </b></footer> </app-card> <app-card> <header><h1style="color:red;">React</h1></header> <content>A JavaScript library for building user interfaces</content> <footer><b>Facebook Open Source </b></footer> </app-card>
<card> <divclass="header"> <h1>Angular</h1> </div> <divclass="content">One framework. Mobile & desktop.</div> <divclass="footer"><b>Super-powered by Google </b></div> </card> <card> <divclass="header"> <h1style="color:red;">React</h1> </div> <divclass="content">A JavaScript library for building user interfaces</div> <divclass="footer"><b>Facebook Open Source </b></div> </card>
<card> <divclass="header"><h1>Typescript</h1></div> <divclass="content">Typescript is a javascript for any scale</div> <divclass="footer"><b>Microsoft </b></div> <p>This text will not be shown</p> </card>
<card> <ng-container> <divclass="header"> <h1style="color:red;">React</h1> </div> </ng-container> <divclass="content">A JavaScript library for building user interfaces</div> <divclass="footer"><b>Facebook Open Source </b></div> </card>
<card> <ng-containerngProjectAs="header"> <div> <h1style="color:red;">React</h1> </div> </ng-container> <divclass="content">A JavaScript library for building user interfaces</div> <divclass="footer"><b>Facebook Open Source </b></div> </card>