Rails: How does MD5 checksum work in paperclip?

流过昼夜 提交于 2019-12-11 05:53:04

问题


I am really confused about this:

from the officially paperclip wiki page:

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

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?

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?


回答1:


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.



来源:https://stackoverflow.com/questions/15282130/rails-how-does-md5-checksum-work-in-paperclip

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!