البحث عن وإنشاء روابط رفع قصيرة

Appears in Post:

![img-MAVMAbkLhcg3sooqMLUyKIhT](upload://>>>>>yygWIAKKT974aRWzlyDof2O82bL<<<<<.jpeg)

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.

?

You would use this function:

and then lookup the SHA1 in the database to find the upload record.

إعجابَين (2)

Ah, so that’s the SHA1? doh!

إعجاب واحد (1)

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)

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)

sorry, early part of the day, so if my goal is to create the short-url, I need to transcode the SHA1 to base62?

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)

Yes, Rails. I’m uploading from the back-end.

OMGoodness:

Upload.last.short_url

"upload://fkO7C9M7SLRhXjEiFTOSUJIdCgJ.jpeg" :tada:

Sorry David, I totally missed that!!

At least this Topic clarifies this all for anyone interested.

Thanks for all the info.

إعجابَين (2)

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.