小编Thi*_*oop的帖子

下载文件时“无法构建‘Blob’:提供的值无法转换为序列”

我正在尝试使用 ajax/jquery 下载并保存 PDF 文件(我知道..)。

这是我在服务器端的:

        public HttpResponseMessage GetPdf()
        {
            var pdf = generatePdfByteArray(); // byte[]

            var result = Request.CreateResponse(HttpStatusCode.OK);
            result.Content = new ByteArrayContent(pdf);
            //result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
            //{
            //    FileName = "blah.pdf"
            //};
// tried with and without content disposition.. shouldn't matter, i think?
            result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");

            return result;
        }
Run Code Online (Sandbox Code Playgroud)

这是客户端:

    let ajaxOptions = {
    url: '/url',
    type: "GET",
    accepts: "application/pdf",
    success: (data) => {
        let blob = new Blob(data, {
            type: "application/pdf"
        }); // <-- this fails …
Run Code Online (Sandbox Code Playgroud)

ajax jquery asp.net-web-api2

16
推荐指数
2
解决办法
2万
查看次数

标签 统计

ajax ×1

asp.net-web-api2 ×1

jquery ×1