简体   繁体   English

如何验证文件是否正确上传?

[英]How can I validate that the file is correctly uploaded?

I'm using following uploader - http://valums.com/ajax-upload/ . 我正在使用以下上传器-http: //valums.com/ajax-upload/ It calls method where I get MultipartFile. 它调用我得到MultipartFile的方法。 The question is: how can I detect the situation that the file is not correctly uploaded - user canceled uploading or something else? 问题是:如何检测文件未正确上传的情况-用户取消了上传或其他操作?

The sample upload server code (it's groovy) 样本上传服务器代码(很时髦)

`def upload = { File file = createTemporaryFile() InputStream inputStream = selectInputStream(request) file << inputStream } `def upload = {文件文件= createTemporaryFile()InputStream inputStream = selectInputStream(request)文件<< inputStream}

private InputStream selectInputStream(HttpServletRequest request) {
    if (request instanceof MultipartHttpServletRequest) {
        MultipartFile uploadedFile = ((MultipartHttpServletRequest) request).getFile('qqfile')
        return uploadedFile.inputStream
    }
    return request.inputStream
}`

Im not sure if there's a 'standard' way, but why not transmit a hash with the file? 我不确定是否存在“标准”方式,但是为什么不与文件一起传输哈希呢?

Once upload is complete, calculate the hash on the server and see if it matches. 上传完成后,计算服务器上的哈希值,看看是否匹配。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM