fedor.belov
fedor.belov

Reputation: 23333

How can I validate that the file is correctly uploaded?

I'm using following uploader - http://valums.com/ajax-upload/ . It calls method where I get 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 }

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

Upvotes: 0

Views: 207

Answers (1)

pauljwilliams
pauljwilliams

Reputation: 19225

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.

Upvotes: 1

Related Questions