English 中文(简体)
JSON的回复是否归还了基64编码档案?
原标题:Should a JSON response return a base64-encoded file?

I m 创建网络服务,接收其他用户“排列”的XPS文件。 因此,我想把由此产生的卷宗合并为一个答复:

"Files":
[
  {"Id": 1, "ContentType": "application/vnd.ms-xpsdocument", "Data": "base64-encoded data of file here" },
  {"Id": 2, "ContentType": "application/vnd.ms-xpsdocument", "Data": "another files base64 data"}
]

这是一种可怕的想法吗? 我是否应当担心? 由于多台服务器将投票选举这一意向书,我真的希望把发出的请求减少到最低限度。 如果能更好地做到这一点,我确实赞赏任何建议。

FWIW, the methods I was Planning to use to base64-encode/decode the files was taken from this question.

最佳回答

Zip/compress the files into an archive? That avoids the base64 explosion of data.

EDIT:正如你在评论中询问如何处理每个档案的元数据一样,请允许我在此总结一下,以便于今后参考:

  1. Put the metadata into the comment field of each zip file entry.
  2. For each file, create a separate file in the archive with the same name plus some key extension (.metadata?) that you put the metadata into.
  3. Embed the metadata into the file name. (I guess this is a new idea)
问题回答

如果业绩是目标,我想到两个答案:

(1) 采用不同的数据格式,方便用户使用,并允许双元数据不转换(有些序列化,或只是原始档案数据之前的结构性序言)。

2) 在某些地方(可能是斜体)保存文件,并单独提出档案要求。

真正的问题是,申请间接费用是否占满足N文件要求所需带宽的很大一部分或时间。

也就是说,需要一定的时间和带宽才能在N的请求中提供N文件(即每一份请求文件)。

在M项请求中(M.C. < N.)可能使用less带宽提供N文件。 然而,带宽储蓄是否很大? 服务器方面的处理是否有任何节余? 固然存在一些交叉点的间接费用,但如果文件是巨大的,带宽的差别将微不足道。 如果每个<><>文件的服务器处理时间大大高于每申请时间,那么节省的费用将微不足道。

尽管如此,如果你能够的话,它通常会打断数据。 我要说的是,第64条保护初等人物是一种坏的想法。 如果您的客户已经建立起来,与“智者”合作,这就是一个极好的想法。 可以通过使服务器自动压缩(通常为gzip)而节省带宽,以支付某些服务器时间的费用。





相关问题
Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How do I compare two decimals to 10 decimal places?

I m using decimal type (.net), and I want to see if two numbers are equal. But I only want to be accurate to 10 decimal places. For example take these three numbers. I want them all to be equal. 0....

Exception practices when creating a SynchronizationContext?

I m creating an STA version of the SynchronizationContext for use in Windows Workflow 4.0. I m wondering what to do about exceptions when Post-ing callbacks. The SynchronizationContext can be used ...

Show running instance in single instance application

I am building an application with C#. I managed to turn this into a single instance application by checking if the same process is already running. Process[] pname = Process.GetProcessesByName("...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...

热门标签