我正在尝试从我的网络服务器检索上传的文件.当客户端通过webform(随机文件)发送文件时,我需要解析请求以获取文件并进一步处理.基本上,代码如下:
HttpListenerContext context = listener.GetContext();
HttpListenerRequest request = context.Request;
StreamReader r = new StreamReader(request.InputStream, System.Text.Encoding.Default);
// this is the retrieved file from streamreader
string file = null;
while ((line = r.ReadLine()) != null){
// i read the stream till i retrieve the filename
// get the file data out and break the loop
}
// A byststream is created by converting the string,
Byte[] bytes = request.ContentEncoding.GetBytes(file);
MemoryStream mstream = new MemoryStream(bytes);
// do the rest
Run Code Online (Sandbox Code Playgroud)
因此,我能够检索文本文件,但对于所有其他文件,它们都已损坏.有人能告诉我如何正确解析这些HttplistnerRequests(或提供轻量级替代)?
我需要读取XLSX文件并从中提取最大量的内容.我应该使用哪种API?
OLE DB,打开XML SDK或Excel Interop?
我有一个只接受.tar.gz文件或.zip文件的服务器.
客户端(在浏览器中)我在内存中有几个Blob,我需要将其推回服务器.
有没有什么办法可以将这些Blob(即添加到zip或tar.gz)文件直接流式传输到服务器?
我想在推回服务器之前避免在内存中使用完整的tar.gz文件.
谢谢
在网页中,我必须读取文件的一小部分,对于许多(1500-12000)小文件来说,每个文件的大小约为1 Mb。收集所需信息后,将其推回到服务器上。
我的问题:我使用FileReader API,垃圾收集无法正常工作,并且内存消耗激增。
代码如下:
function extract_information_from_files(input_files) {
//some dummy implementation
for (var i = 0; i < input_files.length; ++i) {
(function dummy_function(file) {
var reader = new FileReader();
reader.onload = function () {
//convert to Uint8Array because used library expects this
var array_buffer = new Uint8Array(reader.result);
//do some fancy stuff with the library (very small subset of data is kept)
//finish
//function call ends, expect garbage collect to start cleaning.
//even explicit dereferencing does not work
};
reader.readAsArrayBuffer(file);
})(input_files[i]); …Run Code Online (Sandbox Code Playgroud) 我目前正在努力理解 Angular (2+)、HttpClient 和 Observables。
我来自承诺异步/等待背景,我想在角度中实现的目标相当于:
//(...) Some boilerplate to showcase how to avoid callback hell with promises and async/await
async function getDataFromRemoteServer() {
this.result = await httpGet(`/api/point/id`);
this.dependentKey = someComplexSyncTransformation(this.result);
this.dependentResult = await httpGet(`/api/point/id/dependent/keys/${this.dependentKey}`);
this.deeplyNestedResult = await httpGet(`/api/point/id/dependen/keys/${this.dependentResult.someValue}`);
}
Run Code Online (Sandbox Code Playgroud)
我能想到的最好的角度是:
import { HttpClient } from `@angular/common/http`;
//(...) boilerplate to set component up.
constructor(private http: HttpClient) {}
// somewhere in a component.
getDataFromRemoteServer() {
this.http.get(`/api/point/id`).subscribe( result => {
this.result = result;
this.dependentKey = someComplexSyncTransformation(this.result);
this.http.get(`/api/point/id/dependent/keys/${this.dependentKey}`).subscribe( dependentResult => {
this.dependentResult = …Run Code Online (Sandbox Code Playgroud) javascript ×3
c# ×2
angular ×1
file ×1
gzip ×1
httplistener ×1
observable ×1
oledb ×1
openxml ×1
parsing ×1
promise ×1
stream ×1
streamreader ×1
tar ×1
typescript ×1
zip ×1