How to get a post uploads real url?

Hey there!
I have been looking all over the internet for this but had no luck, so I resorted to asking here.

Let me add a bit of context, we are creating a custom front-end using the Discourse user API. Where I was trying to render a post raw content, but images are passed like this: uploads://<id>.png so the browser can’t fetch them.

Is there any way of getting the real URL via the API? like https://custom.discourse.org/uploads/<id>.png or something of the like?

Cheers!

1 Like

See Converting short upload URLs to full URLs

6 Likes

Thanks a lot, I’ll give it a look!

1 Like

Hey @RGJ Just tried the python example code, mentioned here: Converting short upload URLs to full URLs - #2 by michaeld

But it seems it’s not decoding correctly.

This is the code I ended up trying. It should decode to “77f164006403e10d7d40143d525f8a5d69390baf” but I get “77f13112951f458abf39d5e480c59eba10c97f31”, any idea why this might be the case? I’m not that experienced with this kinda stuff

import base62
input = "h73zkifccxqjtevvuahwq9hefkt"
expected = "77f164006403e10d7d40143d525f8a5d69390baf"

decoded = hex(base62.decode(input, base62.CHARSET_INVERTED))[2:].zfill(40)

print('decoded: ' + decoded)

if expected != decoded:
  print('not decoded correctly')
else:
  print('decoded correctly')

My bad, it was being converted to lowercase before I printed the uploads:// link to the console, so decoding did not work. Using the correct casing does work!

Thanks a lot for the quick help!!!

Here is the code I used in flutter to accomplish this:

import 'package:base_x/base_x.dart';
import 'package:hex/hex.dart';

String decodeUploadsLink(String encoded) {
  var base62Rev = BaseXCodec('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ');
  var decodedRev = base62Rev.decode(encoded);
  return HEX.encode(decodedRev);
}
5 Likes