Upload an image without embedding it


(codechef) #1

Hopefully a simple question that I’m over-complicating, but I cannot figure this out. Is there any way to upload an image to a post without embedding it? Basically, I’d want to attach an image file like you would a PDF so that it’s downloadable by clicking it.


(Michael Brown) #2

Sure - just change the markdown generated by the upload as per below:


Original is:

![worksonmymachine|200x193,50%](upload://wD4QT0WxzqkxFMKMI8QRQoRCcWC.png)

resuliting in:
worksonmymachine


Option 1 is:

[worksonmymachine.png](upload://wD4QT0WxzqkxFMKMI8QRQoRCcWC.png)

worksonmymachine.png

EDIT: oops - that one doesn’t actually work… need to specify the full path:

[worksonmymachine.png](//discourse-meta.s3.dualstack.us-west-1.amazonaws.com/original/3X/e/4/e4b06ce98ded89163747305342cf0074d4260202.png)

worksonmymachine.png


Option 2 makes it look like a usual “attachment” upload:

<a class="attachment" href="//discourse-meta.s3.dualstack.us-west-1.amazonaws.com/original/3X/e/4/e4b06ce98ded89163747305342cf0074d4260202.png">womm.png</a> (31443 Bytes)

resulting in:
womm.png (31443 Bytes)

A left-click will still view the image. I don’t believe you can force a user to download the file; that’s controlled by the Content-Disposition header sent by the server.


(Jeff Atwood) #4

Note that this is a very hacky “solution”, it might sort of work as a quick fix but I’m not sure I would recommend it as a general practice.


(codechef) #5

Option 1 was my first attempt, then I fell back to your EDIT :laughing:

Were you able to identify the full url before posting? I’m trying to come up with something that doesn’t require the user to “inspect” the image url in the preview…


(Jeff Atwood) #6

Why don’t you construct the links in angle brackets?

cubicle_sweet_cubicle

https://meta-s3-cdn.freetls.fastly.net/original/3X/e/3/e3a33e7186437ab72d2fdcfb5f45c812ae25a571.gif

<https://meta-s3-cdn.freetls.fastly.net/original/3X/e/3/e3a33e7186437ab72d2fdcfb5f45c812ae25a571.gif>


(Michael Brown) #7

Right-click, Copy image address?


(codechef) #9

Somehow the onebox viewer provides a download link…

image

EDIT: Well, that didn’t demo like I thought it would…


(Jeff Atwood) #10

Did you add the angle brackets as I said?

<https://meta-s3-cdn.freetls.fastly.net/original/3X/e/3/e3a33e7186437ab72d2fdcfb5f45c812ae25a571.gif>


(codechef) #11

Clicking that a link with angle brackets displays the image in the browser rather than downloading it :frowning:

I’m seeing in the image viewer a download link that is a different image URL. Trying to track the source of that link down now…

EDIT: …and determine if that link is available at post time.


(Jeff Atwood) #12

Right click it and select “Save Link As…” – this works on any link in the browser.


(codechef) #13

I know, I know :slight_smile:

The use case is posting items for download as a meeting summary. Those items will sometimes be PDFs, Word docs, slide decks, and images. It would be weird if some some links downloaded and others displayed, right?


(Jeff Atwood) #14

If it’s really so necessary, create a new PDF with the image in it? This is a trivial operation in Word, new doc, paste image, save as PDF.


(codechef) #15

Okay, I have a handful of workarounds to consider. I really appreciate you guys’ help working through this. Thanks for the quick responses. You guys rock @codinghorror and @supermathie!


(codechef) #16

@codinghorror how dangerous is this? I found a solution that works locally, but may not work for CDN scenarios…

  1. Copy the image url from the preview window
  2. Get just the UUID portion
  3. Hack the link to be /uploads/default/{UUID}

For example:

[Cool image to download](/uploads/default/a099b7b187922f26fbebbbb47807fc83da11fc55)

One a scale of 1 to close your computer and go home for the weekend, how dangerous is this?


(Jeff Atwood) #17

@sam says it’ll get deleted by the automatic unreferenced image tombstoning task, so… as predicted… bad idea.


(Sam Saffron) #18

As an admin the hack @supermathie suggested will work if you also upload the image totally normally on a different staff only topic. Or in a PM to yourself. That way it will not be deleted.


(codechef) #19

Is the task looking for the upload:// link in posts?


(Sam Saffron) #20

no it looks for actual images which are linked uploads to the post. I do am no 10000% certain but I don’t think we track an association for A HREF to upload, but maybe I am wrong need to review the code.