Re-using attachments

swatme

Well-known member
ok im on xf 1.2
i suggest to have a re-use of attachment files

example:
you upload an image attachment on thread named "my beautiful wife"
so its now ok...
now you realize, you also need to post the same picture in another thread named "sexy wife".

instead of reuploading the same file which consumes space, why not reuse it instead?
Code:
[attach]123456[/attached]


currently if you just copy "image file url" and use img tag
it will only show when your login, but for unregistered it will
not show the thumbnail.

i hope image reuse is avaialble
 
Upvote 16
green nem orig.webp
Yup ok that's what it was. When you go to More Options, then upload and insert, switch to BB Code Editor, then switch back and click "Preview", it shows the link and not the attachment. But when you submit the post, it then shows the attachment.
 
https://xenforo.com/community/resources/attachment-improvements-by-xon.5042/
by @Xon modifies the image tool in the editor to provide re-use of attachments. When an attachment is reused, a second reference local to the current post is created to the selected prior attachment_data reference and its attachment file. The result is potentially many entries in the attachment table, but only one instance of each attachment_data entry and the file.

https://xenforo.com/community/resources/advanced-attachment-system-aas.5060/
by @au lait has the option to compare the file hash of a new attachment to the file hash in the attachment_data table (i.e. execute a query using the file hash as the selector) but he just blocks the duplicate rather than using the information from the found attachment_data entry to create a new attachment entry for the current post.

I really like @AndyB and his work, but the thought of having multiple copies of the same attachment really bothers me.
 
I do not understand why it currently works the way it does. The attachment table carries the content type, so there is no reason one could not have a media gallery reference in the attachment table that referenced an attachment_data entry that was originally loaded in a post. The developers are reluctant to move the attachment details regarding thumbnail, etc. to the attachment table from the attachment_data table. When that was brought up in another improvement thread it was rejected. If the thumbs were the same size in media, posts and conversations, it would not be a problem.

If someone wanted to create an addon that worked "correctly" they would need to add another attachment_resolve table to handle the conflict.
 
Due to the way XF1 is coded you cannot simply use the same attachment in more than 1 post as an attachment. It looks like this was initially planned by the developers but not carried over to all aspects in the software to support it. So all you can do is duplicate each attachment if needed or reference it as a link to the original attachment.

Indeed the best solution would be to integrate attachments with the Media Gallery. Maybe XF2 will address that with the new XFMG?
 
Due to the way XF1 is coded you cannot simply use the same attachment in more than 1 post as an attachment. It looks like this was initially planned by the developers but not carried over to all aspects in the software to support it. So all you can do is duplicate each attachment if needed or reference it as a link to the original attachment.

Indeed the best solution would be to integrate attachments with the Media Gallery. Maybe XF2 will address that with the new XFMG?

It is not necessary to have duplicated attachment_data or files, it is only necessary to have an attachment entry for each post in the attachment table. I do not know why the XenForo Staff did not implement the feature that way, but I think it had to do with a mistrust of using the file hash for de-duplication. @Xon Attachment Improvements, in fact, does it right but only if one manually chooses to reuse the attachment. In my opinion it should be done automatically if one uploads an attachment that is a duplicate of one already posted on the site.
 
So this fix - for pics showing up in quoted posts:

Code:
<xen:comment>
<xen:if is="!{$validAttachment}">

    <a href="{xen:link full:attachments, $attachment}" target="_blank">{xen:phrase view_attachment_x, 'name={$attachment.attachment_id}'}</a>
    
<xen:elseif is="!{$attachment.thumbnailUrl}" />

    <a href="{xen:link full:attachments, $attachment}" target="_blank">{xen:phrase view_attachment_x, 'name={$attachment.filename}'}</a>
    
<xen:elseif is="{$canView} AND {$full}" />
    
    <img src="{xen:link full:attachments, $attachment}" alt="{$attachment.filename}" class="bbCodeImage LbImage" />
        
<xen:elseif is="{$canView}" />
    
    <a href="{xen:link full:attachments, $attachment}" target="_blank" class="LbTrigger"
        data-href="{xen:link misc/lightbox}"><img
        src="{$attachment.thumbnailUrl}" alt="{$attachment.filename}"
        class="bbCodeImage LbImage" /></a>
            
<xen:else />

    <a href="{xen:link full:attachments, $attachment}" target="_blank"><img src="{$attachment.thumbnailUrl}" alt="{$attachment.filename}" class="bbCodeImage" /></a>
    
</xen:if>
</xen:comment>
<img src="{xen:link attachments, $attachment}" alt="{$attachment.filename}" class="bbCodeImage LbImage" />

If you remove the pic from inside the quotes, I'm pretty sure that it shows the original attachment, doesn't it? All I did was comment out the entire bb_code_tag_attach template and add the last line.
 
If you have the attachment code, it will open the light box and do the other attachment magic for you. You can always use the image file as an image, but if you like thumbnails (and we only use thumbnails) then creating an IMG bbCode with the attachment file is not what you need.

i.e. none of the attachment options work on it.

You can emulate an attachment by inserting a smaller image as the thumbnail and making it reference the larger image. (You can do that with any pair of image files.)

Since we are using AndyB's Convert Image things get confusing pretty quickly.

In my opinion, it is much simpler and cleaner to create another entry in the xf_attachment table, in which case it really is an attachment, not attachment resources being used in an image link reference.
 
Lots of good insight here, some of which I don't follow/understand. But what I do agree on is that attachments need to be managed better, and in the core IMO.
What needs to happen is that the media gallery and attachment system should become one. We have people uploading the same picture in the attachment system over and over again because they can't easily reuse them when creating new content. That is crazy.

^this
 
We got a death notice from Google today that our vBulletin site will start to throw warnings on most of our pages. I am not willing to upgrade it to support https/ssl, so we will need to make our final move soon.

When I was describing to our members how attachments and galleries would work on the new site, it occurred to me that the duplicate recognition code would be very useful as a search tool. I would like to be able to upload a file in the search dialog and have the file hash created for the new file and then a search performed on that file hash in the xf_attachment_data table. That would allow a person to find all previous posts that had used the potential attachment.

Has anyone ever done that? It seems like it would not be all that difficult.
 
@AndyB I've been using your workaround that you posted in post #2 of this thread for a while and just discovered that it creates a level of confusion that I did not anticipate.

When using the default template, if you preview a post, you see the "view attachment 12345" text/link. When using your template edit, you don't see anything to indicate that there is an attachment. The editor automatically shows the inserted image, but if you aren't aware of this and scroll a bit (sometimes the photos are added to the editor and the scroll position stays where it is, so you have to scroll down to see that pics were added) then you click "preview" one might think they weren't successfully inserted. I've seen this many times - someone posts a thread with 15 pictures, but it's the same 3 pic inserted 5 times. They keep clicking "insert all" then "preview" and see nothing, so out of frustration, they keep clicking.

Is there a "best of both worlds" scenario here? Maybe a better template edit, where they can see the pic in a quote, but would still see a text placeholder for an attachment in the preview when composing?

This issue is completely resolved in XF2, however anyone still using XF1 is left hanging.
 
Is there a reason that you force no thumbnails in that addon? @ondsen posted that he had a version that allowed thumbnails but the link he posted is invalid. I prefer allowing flexibility, that's all.

Also does your addon solve the issue I described, or does it just do the same thing as the workaround in the form of an addon?
 
Top Bottom