Last Updated: February 25, 2016
· timfernihough
Tim january

How to generate test files for uploading during development or troubleshooting

We recently had a client request for improvement to a form where the specific size of a file upload was causing a problem. This meant that to test our use cases properly, I needed some files to upload that were specific sizes:

ie, a file that was greater than 2MB but less than 32MB.
ie, a file that was greater than 32MB but less than 256MB.
ie, a file that was greater than 256MB but less than 512MB.

I read a really useful post on how to generate test files of particular file size on the common OS platforms on Stottmeister's Blog that proved quite useful for me.

Mac OS:

mkfile <file size> <filename>


mkfile 40M testfile.txt


dd if=/dev/zero of=<filename> bs=<initial blocksize in bytes> count=<iterations of the blocksize>


dd if=/dev/zero of=testfile.txt bs=28M count=1


C:\>fsutil file createnew <filename> <filesize in bytes>


C:\>fsutil file createnew C:\testfile.txt 1024

The process to create these files is pretty quick too - so it's much easier to generate a test file than to search around your hard drive for a file of appropriate size. Not to mention - if you work with many clients; you don't want to be uploading files that belong to other clients just so you can test a use case.

Say Thanks

5 Responses
Add your response

12003957 10206752435102297 2524621803006121539 n

This is great, thanks for all the different examples.

over 1 year ago ·

Awesome, thanks! I never knew there's even a built-in utility on Windows!

over 1 year ago ·
Tim january

Glad that it was helpful to you guys!

over 1 year ago ·
Profile pic

That's great, thanks for sharing. Another useful thing to test for with file uploads is to upload a document containing a string that looks like MIME part separator! One of our vendors had a problem with a specific document being uploaded that contained the string: ==00OO00== and their mime decoder truncated the file there!

over 1 year ago ·
Tim january

@alchemycs I could definitely see that being a pain point for sure! If you are writing your own upload library, I could see that being something the developer could easily control but if they are using something pre-built like the Webforms in Drupal; wonder how we'd be able to get around that? Creating a patch and submitting it against the Webform Module I guess. :)

over 1 year ago ·