<p>It is related to the linked question since any images uploaded through Craft's <a href="https://craftcms.com/classreference/services/AssetsService" rel="nofollow">AssetsService</a> go through a "cleansing" process to remove any potentially embedded malicious scripts so the file size will inevitably be +/- the original by a small percentage.</p>

<p>What you can do is instead of uploading through the AssetsService, programmatically copy the file to the final destination on the file system in an Asset Source, then trigger Asset indexing like how the <a href="https://craftcms.com/classreference/controllers/ToolsController" rel="nofollow">ToolsController</a> does for the <a href="https://craftcms.com/classreference/tools/AssetIndexTool" rel="nofollow">AssetIndexTool</a>.  That will bypass any cleansing operations.</p>

CC BY-SA 3.0
2016-04-26T17:32:11.250Z
2016-04-26T17:32:11.250Z
Brad Bell
<p>I'm writing a plugin which synchronizes the content from an external database with the Craft database.</p>

<p>For the images I receive URL's to the external image then store them in the temp storage and upload them to Craft assets, which works fine.</p>

<p>I now want to check additionally if the image in the temp already exists in crafts assets and if the images are identical ( checking for file size ).</p>

<p>Ideally comparing the external image and the image in the assets even before saving the external one to the temp.</p>

<p>The file size from the external source is identical to the tmp saved file but after uploading the file to Craft it somehow gets a little bit bigger so checking for the file size doesn't work.</p>

<p>Am I doing something wrong ? Should I check for something else than filesize?</p>

<p>This might be related to <a href="https://craftcms.stackexchange.com/questions/14784/is-there-any-way-to-prevent-craft-from-doing-anything-with-uploaded-gif-assets">this question</a></p>

<plugin-development><assets>
Check if local image differs from image on Craft
# Check if local image differs from image on Craft

(Asked by: username_0 on 2016-04-26)

I'm writing a plugin which synchronizes the content from an external database with the Craft database.

For the images I receive URL's to the external image then store them in the temp storage and upload them to Craft assets, which works fine.

I now want to check additionally if the image in the temp already exists in crafts assets and if the images are identical ( checking for file size ).

Ideally comparing the external image and the image in the assets even before saving the external one to the temp.

The file size from the external source is identical to the tmp saved file but after uploading the file to Craft it somehow gets a little bit bigger so checking for the file size doesn't work.

Am I doing something wrong ? Should I check for something else than filesize?

This might be related to [this question](https://craftcms.stackexchange.com/questions/14784/is-there-any-way-to-prevent-craft-from-doing-anything-with-uploaded-gif-assets)

**Tags:** plugin-development, assets

---

## 1 answers

### Answer by username_1 on 2016-04-26. Score: 1 | Accepted answer

It is related to the linked question since any images uploaded through Craft's [AssetsService](https://craftcms.com/classreference/services/AssetsService) go through a "cleansing" process to remove any potentially embedded malicious scripts so the file size will inevitably be +/- the original by a small percentage.

What you can do is instead of uploading through the AssetsService, programmatically copy the file to the final destination on the file system in an Asset Source, then trigger Asset indexing like how the [ToolsController](https://craftcms.com/classreference/controllers/ToolsController) does for the [AssetIndexTool](https://craftcms.com/classreference/tools/AssetIndexTool). That will bypass any cleansing operations.


---

