Rails:MD5 校验和如何在回形针中工作? [英] Rails: How does MD5 checksum work in paperclip?

查看:61
本文介绍了Rails:MD5 校验和如何在回形针中工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的很困惑:

来自官方回形针维基页面:

from the officially paperclip wiki page:

分配的原始文件的 MD5 校验和将放置在模型,如果它有一个名为指纹的属性.

A MD5 checksum of the original file assigned will be placed in the model if it has an attribute named fingerprint.

我的表中有一个 attachment_fingerprint,回形针会自动将 md5 值插入该字段.

I have a attachment_fingerprint in my table and paperclip will insert the md5 value into that field automatically.

问题是,校验和是如何生成的?是上传前生成的还是上传后生成的?

The question is, how is the checksum generated? is it generated before the upload or after the upload?

例如,原始文件的校验和为 1,文件在上传过程中损坏,现在校验和变为 2,回形针将插入哪个值?

For example, the original file has a checksum 1 and the file get corrupted during the uploading process and its checksum now become 2, which value will paperclip insert into the field?

推荐答案

在文件成功上传到服务器后计算指纹校验和并将其保存到指纹列.不过,文件在上传过程中被损坏的可能性很小.如果您真的很担心这一点,则必须在客户端预先计算相同的 MD5,将其与上传的文件一起发送,然后在服务器上根据 Paperclip 计算的一个数据检查原始 MD5 哈希值.

The fingerprint checksum is computed and saved to the fingerprint column after the file has been successfully uploaded to server. It's very unlikely that the file would get corrupted during the upload process, though. If you're really concerned about this, you'd have to precompute the same MD5 on the client, send it along with the uploaded file and on the server check the original MD5 hash against the one Paperclip computes.

这篇关于Rails:MD5 校验和如何在回形针中工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆