小编cec*_*mel的帖子

Httplistener和文件上传

我正在尝试从我的网络服务器检索上传的文件.当客户端通过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(或提供轻量级替代)?

c# parsing httplistener httplistenerrequest streamreader

11
推荐指数
2
解决办法
1万
查看次数

OLE DB与OPEN XML SDK vs Excel.interop

我需要读取XLSX文件并从中提取最大量的内容.我应该使用哪种API?

OLE DB,打开XML SDK或Excel Interop?

  • 哪个最容易使用?
  • 你能用一个或另一个来检索所有信息吗?即日期,时间,合并单元格,表格,数据透视表等

c# oledb openxml

11
推荐指数
1
解决办法
8708
查看次数

将blob添加到tar并使用JavaScript流式传输到服务器

我有一个只接受.tar.gz文件或.zip文件的服务器.

客户端(在浏览器中)我在内存中有几个Blob,我需要将其推回服务器.

有没有什么办法可以将这些Blob(即添加到zip或tar.gz)文件直接流式传输到服务器?

我想在推回服务器之前避免在内存中使用完整的tar.gz文件.

谢谢

javascript zip gzip stream tar

10
推荐指数
1
解决办法
564
查看次数

FileReader:使用javascript读取许多文件而不会发生内存泄漏

在网页中,我必须读取文件的一小部分,对于许多(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)

javascript file

5
推荐指数
1
解决办法
2197
查看次数

使用 Angular、HttpClient 和 Observables 避免回调地狱

我目前正在努力理解 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 promise observable typescript angular

2
推荐指数
1
解决办法
1995
查看次数