# How to avoid uploading attachments multiple times in a migration

**URL:** <https://meta.discourse.org/t/how-to-avoid-uploading-attachments-multiple-times-in-a-migration/70613>\
**Category:** Development\
**Created:** [2017 年 9 月 22 日午後 10:35 UTC](https://meta.discourse.org/t/how-to-avoid-uploading-attachments-multiple-times-in-a-migration/70613 "2017-09-22T22:35:48Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)\
**Post date:** [2017 年 9 月 22 日午後 10:35 UTC](https://meta.discourse.org/t/how-to-avoid-uploading-attachments-multiple-times-in-a-migration/70613/1 "2017-09-22T22:35:48Z")

</div>

The vbulletin importer currently includes only attachments that are included in `[attach]` tags in the text of the message. But sometimes there are attachments not included in the text, and they don’t get imported.

I’ve fixed this with a function that after posts are processed, reads all the attachments, uploads them, replaces the `[attach]` codes, and if the attachment was not mentioned in the text adds a link to it at the end of the post.

The problem is how to avoid re-uploading and including them with subsequent runs of the importer. My current solution is to put `<div class="vbulletin-attachments-imported"></div>` at the end of the post and to check for that string before handling attachments.

It works, but is there a more elegant way? (And, I suppose if I were more clever, I’d have a solution that did this on a per-attachment rather than per-post level, but it’s hard to imagine that such a feature would ever be used.)

---

_[View the full topic](https://meta.discourse.org/t/how-to-avoid-uploading-attachments-multiple-times-in-a-migration/70613)._
