איך להשיג כתובת URL אמיתית להעלאת פוסט?

סיכום מבוסס בינה מלאכותית

The discussion revolves around obtaining the real URL of uploaded files via the Discourse API. keff is trying to render raw post content in a custom front-end but images are passed as uploads://<id>.png which the browser cannot fetch.

RGJ suggests referring to a meta topic for a solution. keff attempts to use the provided Python example but encounters decoding issues. However, keff eventually resolves the problem, realizing it was due to incorrect casing.

keff shares a successful implementation of the code in Flutter, using the base_x and hex packages to decode the uploads link. The solution involves decoding the base62 encoded string and then converting it to hexadecimal.

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!

See Converting short upload URLs to full URLs

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

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);
}