Appears in Post:

How can I map it to this (and vice versa):
"//127.0.0.1:4200/uploads/default/original/1X/abcafdf0e1d9262d515075420e4d940718796a5d.jpeg"
appears as url
property of an Upload
.
?
david
(David Taylor)
April 25, 2025, 8:09am
2
You would use this function:
and then lookup the SHA1 in the database to find the upload record.
2 Likes
Ah, so that’s the SHA1? doh!
1 Like
david
(David Taylor)
April 25, 2025, 8:12am
4
Yeah, the both the short-url and the regular URL include the SHA1.
The difference is that the long URL uses the original hex-encoded version, which matches the one in the database. The upload://
“short url” is a base62 representation of the same hash, so that it uses fewer characters.
1 Like
Sorry, right got it.
So there is a:
short-url
in the Post
url
- original long url to upload.
SHA1
generated during upload.
and you just gave me the way to find the url
from the short-url
1 Like
sorry, early part of the day, so if my goal is to create the short-url
, I need to transcode the SHA1 to base62?
david
(David Taylor)
April 25, 2025, 8:25am
7
Where are you doing this? In the Rails app?
If so, then you can generate the URLs using upload.short_url
and upload.url
.
To find an upload record in the first place, you can do:
sha1 = Upload.sha1_from_long_url(...)
# or
sha1 = Upload.sha1_from_short_url(...)
# then
upload = Upload.find_by(sha1: sha1)
1 Like
Yes, Rails. I’m uploading from the back-end.
OMGoodness:
Upload.last.short_url
"upload://fkO7C9M7SLRhXjEiFTOSUJIdCgJ.jpeg"
Sorry David, I totally missed that!!
At least this Topic clarifies this all for anyone interested.
Thanks for all the info.
Upload
.where(dominant_color: nil)
.order("id desc")
.first(count)
.each { |upload| upload.calculate_dominant_color! }
end
private
def short_url_basename
"#{Upload.base62_sha1(sha1)}#{extension.present? ? ".#{extension}" : ""}"
end
end
# == Schema Information
#
# Table name: uploads
#
# id :integer not null, primary key
# user_id :integer not null
# original_filename :string not null
2 Likes