3

I'm using fswebcam to take pictures from my webcam and write them to /var/www so that anybody can view them from my website.

The problem is that my server is a Raspberry Pi with a slow SD card. It takes several seconds to write the image to the SD card. If a user requests the image while it is still being written, they'll get a half-finished version of the image:

Is it possible to make Apache wait for an image to be fully written before it serves it?

2
  • 1
    How often are images saved? Are you always overwriting the same image or is there a timestamp incorporated into the filename? How is the HTML page generated that displays the image?
    – MrWhite
    Oct 24, 2015 at 10:16
  • Without an example of how you are doing this it is difficult to provide an answer. The solution will almost certainly be a Bash conditional construct or a specific list of commands like this: Take photo > write photo to card > mv or cp newly written photo to Apache directory to be served from. cp next.jpg current.jpg or something basic like that? Oct 25, 2015 at 8:09

2 Answers 2

2

Moving a file within the same disk is a very quick (nearly instantaneous) operation. Instead of saving them directly to www save them to a different directory on the same disk where Apache can't see them. Then when they are fully saved, move them into place in www.

1
  • This is what I ended up doing, and it worked perfectly. Thanks to you and Tom Brossman for the idea. Dec 23, 2015 at 15:07
0

I'm not sure about apache but I think some scripting language should be able to detect if a file is being written (perhaps using file handles?)

You can then wait for it to finish and serve the file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.