Table of Contents
hide
What You Need
- A Filestack account. You can sign up for free if you don’t have one.
- Somewhere to receive webhooks. In production that’s a route on your own server. For this guide we used a free Beeceptor endpoint so we could watch the requests arrive.
- A page with the File Picker on it. A blank HTML file served locally works fine.
How the Scan Works
Virus detection only runs inside a workflow. Other tasks can run straight from a CDN URL (resize is one). Virus detection can’t. Here’s the order things happen in. A file is uploaded and stored. Then the workflow starts and the scan reads the file’s contents. Since it reads the bytes, renaming a file or changing its extension doesn’t hide it. The scan runs after the upload has finished, so your users don’t wait for it. When it’s done, Filestack sends the result to your webhook. (You can also poll the workflow status endpoint for it.) The result has two fields: infected, which is true or false, and infections_list, which names anything it found. The full details are in the virus detection documentation.Creating the Workflow
In the portal, open Workflows from the sidebar. At the top there are templates (Web-Ready Images, Blur Faces, Square Thumbnail). None of them scans for viruses, so click Create New.
Pointing the Webhook at Beeceptor
Before uploading anything, you need somewhere for the results to land. For this guide we opened Beeceptor, which gives you a free public URL and shows each request it receives.
Adding the Workflow to the Picker
Go back to the workflow and click Picker configuration. You’ll get picker code with your API key and this workflow’s ID already in it.
Testing With a Clean Photo
First we uploaded something harmless, a 2 MB photo of a puppy called pup.jpg.
Testing With the EICAR File
You don’t want real malware on your laptop just to test a scanner, and you don’t need it. The EICAR test file exists for exactly this. It was created by EICAR (the European Institute for Computer Antivirus Research) together with CARO (the Computer Antivirus Research Organization). It’s a 68-byte text file containing a single line: X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H* It doesn’t do anything. Antivirus engines flag it on purpose so you can check that scanning works.
- text.sources holds the file handle. That’s how you tie a verdict to a file in your database.
- text.results.virus_detection_1.data holds the verdict. The key is the task name you picked, so if you rename the task, update your code.
- text.status is Finished once every task in the workflow has run.
Things to Sort Out Before Production
The scan doesn’t stop the upload. Look at sources in the infected payload: the EICAR file got a handle, so it’s sitting in storage. Virus detection tells you what’s in a file, and what happens next is up to you. One approach is to keep each upload in a “pending” state in your app until its webhook arrives, and only show or serve files with infected: false. Another is to add a second task to the same workflow that only runs when the scan comes back clean, so your app only ever serves the clean copy. You can also add steps for flagged files, like removing them or alerting someone on your team. Verify the webhook signature. Your webhook URL is public. Without a check, anyone who finds it can POST a payload saying a file is clean. Give the webhook a secret in the portal. Then, on your server, build the string [FS-Timestamp].[Content] from the FS-Timestamp request header and the raw request body, sign it with HMAC-SHA256 using that secret, and compare the result with the signature Filestack sent. The webhooks docs cover this, with Node.js and PHP examples. Do this before your code trusts a verdict. Decide what users see while the scan runs. The verdict took about 10 seconds in our tests. Plan for a state where the file is uploaded but not yet cleared, and for a scan that takes longer than usual. A slow scan shouldn’t count as a clean one.Key takeaways
- Virus detection only runs in a workflow. Unlike
resizeand other URL tasks,virus_detectioncan’t be called from a CDN URL. It runs after the file is stored and reads the actual bytes, so renaming a file or changing its extension won’t hide it. - The setup is three pieces. You need a workflow with one
virus_detectiontask, a webhook with the event type set to Workflow, and the workflow ID in the picker’sstoreTo.workflowsoption. - One picker line turns scanning on. Without
storeTo.workflows, the picker uploads exactly as before. With it, every upload through that picker goes through the scan. - The task name is part of your contract. The verdict arrives under
text.results.<task name>.data, so renaming the task in the portal means updating your code. - The verdict is small and easy to act on. It has
infected(true or false) andinfections_list, whiletext.sourcesgives you the handle to tie it back to a file. - Test with EICAR, not real malware. The 68-byte EICAR test file is flagged on purpose and comes back as
content.malicious.eicar-test-signature. - Scanning doesn’t block the upload. An infected file still gets a handle and sits in storage. Keep uploads pending until a clean verdict arrives, or chain a second task that only runs on clean files.
- Verify every webhook. Sign
[FS-Timestamp].[Content]with HMAC-SHA256 using your webhook secret and compare it with Filestack’s signature before trusting any verdict. - Design for seconds, not milliseconds. The verdict took about 10 seconds in testing, so plan a “still scanning” state, and never treat a slow scan as a clean one.
Further reading
| Topic | Link |
|---|---|
| Virus detection task, logic and payloads | Virus detection docs |
| Creating workflows and attaching them to uploads | Workflows docs |
| Webhook events and signature verification | Webhooks docs |
| Starting from an empty account | Get a free Filestack API key |
Wrapping Up
The whole setup was a workflow with one virus_detection task, a webhook with the Workflow event type, and the workflow ID in the picker’s storeTo options. Most of the remaining work is deciding what your app does when a file comes back flagged. Happy coding.
Favour is a Developer Relations engineer with 4+ years of experience helping developers adopt and succeed with technical products. Combining a strong software engineering background with a passion for community building, content creation, and developer education, he specializes in translating complex technologies into clear, engaging experiences for developer audiences.
Read More →


