Partial copy from https://github.com/Rovak/InlineAttachment
We need to make some changes to handle xhr errors. Given than the repo hasn't been updated in 7 years, and it's a hassle to push the changes or fork the repo, just copy over the required files.