我将创建一个方法来通过url和csvtojson读取cvs文件,但是当我使用request.get时,我会得到Argument of type 'string' is not assignable to parameter of type 'Readable'。我创建了document,但是Document,但是问题仍然存在。更重要的是,我可以使用另一个npm从url中读取文件,但我认为,这些进程可能存在于csvtojson中。因此,我将使用另一个npm来处理url数据,或者我该如何解决这个问题?
import { injectable } from "inversify";
import { BaseController } from "controllers/BaseController";
import * as csv from "csvtojson";
import {
Path,
POST,
Description,
CheckPermission,
Tags,
Authorization,
Param,
ContextRequest
} from "../../../lib/rest";
import { Action } from "../../../config/action-right";
import * as express from "express";
@injectable()
@Path("/api/import")
@Tags("Import")
export class ImportController implements BaseController {
@Description("")
@POST("/v1/import")
@Authorization
@CheckPermission(Action.Read)
async import(
@ContextRequest request: express.Request,
@Param() filePath: string
): Promise<any> {
csv()
.fromStream(request.get("https://akhura.com/test.csv"))
.on("csv", (csvRow) => {
return csvRow;
})
.on("done", (error) => {
return error;
});
}
}错误:
[ts] Argument of type 'string' is not assignable to parameter of type 'Readable'.
发布于 2018-09-24 17:43:42
代码片段中的request对象是Express.Request,而不是node.js request模块。
在Express中,Request.get从请求标头中返回指定键的字符串形式的值
https://stackoverflow.com/questions/52475973
复制相似问题