【问题标题】:RestSharp addfile sends file with ".undefined" file extensionRestSharp addfile 发送带有“.undefined”文件扩展名的文件
【发布时间】:2021-08-25 11:41:48
【问题描述】:

我正在使用以下代码将 PDF 文件上传到 node.js 服务器:

var file = new FileContentResult(...)
var client = new RestClient(_tenantOptions.BaseUrl + _tenantOptions.UploadPdfFilesUrn) {Timeout = _tenantOptions.RequestTimeoutMilliseconds};
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", accessToken);
request.AddFile("file", file.FileContents, file.ContentType);
var response = client.Execute<UploadFileResponse>(request);

这个文件出现在像filename.undefined 虽然file.ContentType = "application/pdf" 这样的服务器上。我错过了什么?

【问题讨论】:

    标签: c# restsharp


    【解决方案1】:

    根据the source code for RestSharpAddFile 的 4 参数形式也接受文件名。

    试试

    request.AddFile("file", file.FileContents, "document.pdf", file.ContentType);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-05-04
      • 2013-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多