文件上传到Web API 2时,非英文字符在文件名中出现乱码

时间:2015-03-09 08:41:19

标签: asp.net asp.net-web-api asp.net-web-api2 multipart

我使用dropzone.js将文件上传到Web API 2服务。读取多部分流会出现乱码的俄语字符。例如,当我上传名为Русскоеназвание的文件时 - 俄语字符会给出????? ?????? - 俄罗斯人物。

我确信dropzone.js工作正常,这只是一个Web API问题。

这是GetStream方法。

public override Stream GetStream(HttpContent parent, HttpContentHeaders headers)
        {
            // For form data, Content-Disposition header is a requirement
            ContentDispositionHeaderValue contentDisposition = headers.ContentDisposition;
            if (contentDisposition != null)
            {
                // We will post process this as form data
                _isFormData.Add(String.IsNullOrEmpty(contentDisposition.FileName));

                return new MemoryStream();
            }

            // If no Content-Disposition header was present.
            throw new InvalidOperationException(
                string.Format("Did not find required '{0}' header field in MIME multipart body part..",
                              "Content-Disposition"));
        }

1 个答案:

答案 0 :(得分:0)

这可能是js方面的错误编码。正如你发布的而不是“Русскоеназвание - 俄文字符”你得到“????? ?????? - 俄文字符”,这意味着该文件是由英文字符支持但没有俄文字符。尝试将编码更改为支持cyrylic字符的编码。 这可能会有所帮助:http://en.wikipedia.org/wiki/Character_encoding

相关问题