开发者

Is there a way to URL shortening in Java to store conveniently into databases

I have requirement where as an attachment user can add a link from sharepoint So that we can save the link[path] of the attachment instead of actual attachment. For this we are planning to design a column which is varchar(512) . Intially we thought this would fit any type of URLs effectively ,but sometimes we found this is too tight for saving into Databases. My points are

  1. Is this a correct desi开发者_如何学运维gn .
  2. We plannned to use TinyURL.com but we cannot gurantee all users have Internet(target users are with in org can or cannot access Internet). So ruled out this option.
  3. Does java provides any API for shortening URLs.

Thanks in advance


In general, URLs cannot be shortened without removing useful information. Services such as TinyURL.com work by maintaining a database of "short URL" to "full URL" mappings. If you want to shorten URLs you would need to implement something like this yourself internally, so a separate table would be required anyway to hold this mapping. You would be just moving the problem somewhere else.

I guess you will just need to define a suitable URL length limit and define your column accordingly.


Any API is an interface to an application, so behind that API there must be an application that saves a mapping from the shortened link to the original link. For this you need a table with two columns, one of them with more than 512 characters.

In short, you'd just introduce another piece of complexity only to workaround your current database schema. Why not just adapt the schema of your existing application to allow for more than 512 characters? To me this seems the most appropriate change if your links can be more than 512 characters long.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜