Rails: Is there a way to check for incomplete JPG file upload?

Posted by user206481 on Stack Overflow See other posts from Stack Overflow or by user206481
Published on 2010-06-08T16:38:36Z Indexed on 2010/06/08 16:42 UTC
Read the original article Hit count: 207

Filed under:
|
|
|

I have a Rails app that processes and serves up jpg files that were uploaded via FTP. On several occasions the FTP process was disconnected and left many incomplete .jpg files. I was surprised to see that the incomplete jpgs behave as normal jpg files in my app even tho they have incomplete image data.

I have since implemented a more robust FTP process where the uploaded file is initially *.tmp and gets renamed to .jpg after an FTP success code is received.

My problem is, I still have all of these incomplete jpg files on the server and can't figure out how to programmatically weed them out. I can actually display them in a view without generating any errors, but there is only a partial image there. I tried RMagick but they all successfully load (using Image.read) and report the valid x & y resolutions. I have so far not been able to determine a way to programmatically differentiate between an incomplete and complete jpg uploaded image.

Any ideas?

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ftp