【发布时间】:2022-11-16 14:31:11
【问题描述】:
我创建了用于在 FTP 服务器上上传多个文件的 Function App。我已经收到所有使用req.Form.Files 的文件。但是当我收到请求时。我实际上是从 req.Body 中的 HttpClient 请求中找到我的文件的。当我在 Body->FormData 中从 Postman 上传文件时,它工作正常但现在我需要通过代码发送带有文件的发布请求。
我曾参考Sending a Post using HttpClient and the Server is seeing an empty Json file此链接尝试过以下代码。
HttpContent content = new StreamContent (stream);
content.Headers.ContentType = new MediaTypeHeaderValue("multipart/form-data");
HttpResponseMessage response = client.PostAsync ("url", content).Result;
但我想要文件在req.Form.Files 中。用户可能上传了多个文件或一个文件。
注意:现在我有一个由代码生成的文件。但它不应该保存在本地,所以我正在尝试发送流。在HttpContent
【问题讨论】:
-
请更喜欢
await而不是.Result
标签: c# file-upload azure-functions httprequest httpclient