0

有谁知道如何将单个对象中的一系列 PDF 文件从 RESTful WebService 返回到 Javascript 客户端?

我尝试在 JSON 对象中将 PDF 作为字节数组返回,但这似乎不起作用,或者我对 JS 端的字节数组做错了什么。

4

1 回答 1

0

First you need encode your binary files( your pdf files). The base 64 encoding is designed to make binary data survive transport through transport layers that are not 8-bit clean.

I would suggest you to create a function to return one document and return a json object with some of the attributes of the file( name, extension, date,...etc.., content) and in the content field of the json object, just put the base64 string that you obtained from applying the base64 enconding function to the pdf file. In this way you can (in the client side) decode this string and get the original file without any problem.

Base64-encoded data takes about 33% more space than the original data.

Because of this I suggest you to return only one document on each call to the RESTful web service. Becasue a pdf file can be small, but it can also be huge, and combining several documents on the response json object could make your transfer very heavy. But this is up to you.

于 2012-09-24T18:56:23.597 回答