Via Filewatcher, listen for images uploaded via the web and compress

Source: Internet
Author: User

Demand is such, through the web transmission over the picture, whether it is JS upload, or other upload method, you need to generate 2 thumbnails, respectively, for the product list of the small figure small, and for the share of the small figure share. Depending on the different upload methods, the EXE program can be used to easily fit all situations, so there are the following solutions.   First is the use of simple filewatcher, we only need to listen to the Create event. Because small and share are all in the same folder, there is no need to monitor changes to subfolders.  this.filewatcher.path = Tbdir.text;filewatcher.notifyfilter = Notifyfilters.lastwrite | notifyfilters.lastaccess | Notifyfilters.filename | Notifyfilters.creationtime;filewatcher.includesubdirectories = false;  #region Trigger event filewatcher.created + = new FileSystemEventHandler (filewatcher_create); #endregion   where filewather_create is the key implementation method, there will be a pit. File upload needs to consider the integrity of the upload file, that is, if the following code to obtain picture information, because the image size is incorrect, or the picture file is corrupted, resulting in the picture compression failed.  image Imgphoto = Image.FromFile (FilePath)   Therefore, here I can only simply think that a picture can be uploaded within 2 minutes (because before uploading, you can use the text prompt way, Prompt the user not to upload too big picture), simply sleep a bit.  thread.sleep, String filePath = E.fullpath; filezip (FilePath, E.name);  when implementing the Filezip method, You need to consider the Dispose picture file, and use GC to clean up the cache, otherwise there is a risk of out-of-memory behavior. The specific implementation code is not detailed here.   In order to ensure the integrity of the thumbnail, listen to the folder at the same time, using the timer, every 30 minutes to all the pictures to do a traverse check, the uncompressed image is re-compressed.  while (true) {    Thread.Sleep ($ * +);    Allfilezip ();}   Start debugging, seemingly normal operation, rest assured to go to bed ...

Through Filewatcher, listen to images uploaded via the web and compress

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.