How would I validate that a jpg file is a valid image file. We are having files written to a directory using FTP, but we seem to be picking up the file before it has finished writing it, creating invalid images. I need to be able to identify when it is no longer being written to. Any ideas?
相关问题
- Views base64 encoded blob in HTML with PHP
- How to get the background from multiple images by
- $ENV{$variable} in perl
- CV2 Image Error: error: (-215:Assertion failed) !s
- Is it possible to pass command-line arguments to @
相关文章
- What is the best way to create a lock from a web a
- Use savefig in Python with string and iterative in
- Where does this quality loss on Images come from?
- Specifying image dimensions in HTML vs CSS for pag
- How to insert pictures into each individual bar in
- Running a perl script on windows without extension
- How do I append metadata to an image in Matlab?
- Comparing speed of non-matching regexp
I had something similar come up once, more or less what I did was:
Again looking at the FTP issue rather than the JPG issue.
I check the timestamp on the file to make sure it hasn't been modified in the last X (5) mins - that way I can be reasonably sure they've finished uploading
Easiest way might just be to write the file to a temporary directory and then move it to the real directory after the write is finished.
Or you could check here.
EDIT:
Image::TestJPG might be even better.
You're solving the wrong problem, I think.
What you should be doing is figuring out how to tell when whatever FTPd you're using is done writing the file - that way when you come to have the same problem for (say) GIFs, DOCs or MPEGs, you don't have to fix it again.
Precisely how you do that depends rather crucially on what FTPd on what OS you're running. Some do, I believe, have hooks you can set to trigger when an upload's done.
If you can run your own FTPd, Net::FTPServer or POE::Component::Server::FTP are customizable to do the right thing.
In the absence of that:
1) try tailing the logs with a Perl script that looks for 'upload complete' messages 2) use something like
lsof
orfuser
to check whether anything is locking a file before you try and copy it.Have the FTP process set the
readonly
flag, then only work with files that have thereadonly
flag set.