gpt4 book ai didi

javascript - 尝试上传文件时无法读取未定义的属性 'length'

转载 作者:行者123 更新时间:2023-12-02 23:10:17 30 4
gpt4 key购买 nike

我正在尝试上传任何文件扩展名的文件。我正在上传帖子,但是当运行该函数时,它崩溃并出现错误:“无法准备未定义的属性‘长度’”

upload(fileToUpload: File): Promise<FileResponse[]> {
const formData: FormData = new FormData();

formData.append('fileKey', fileToUpload, fileToUpload.name);
return this.http
.post<FileResponse[]>(this.baseUrl + this.urlUpload, formData, { headers: {'Content-Type': undefined }})
.toPromise().then((response) => {
console.log(response);
return response;
}).catch((e) => {
console.log(e);
return e;
});
}

这是我的后端 C#:

        [HttpPost]
[Route("upload")]
[DisableFormValueModelBinding]
[RequestSizeLimit(104857600)]
public async Task<IActionResult> Upload()
{

var fileUploaded = await _fileService.UploadFile(FormOptions, reader);
return Json(new StandardResult<List<FileResponse>>(HttpStatusCode.Created, fileUploaded).Reply);
}

有什么解决办法吗?

最佳答案

我认为这是针对这一行的:

{'Content-Type': undefined }

或者删除此行或放置通用“类型”,例如application/octet-stream

更多信息:https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types

关于javascript - 尝试上传文件时无法读取未定义的属性 'length',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57402913/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com