Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java

# Hash salt for shortened URLs giflib.hash.salt

Does anyone understand where this

Hash salt for shortened URLs

giflib.hash.salt = xOBtdmJZxRcz^jkkyHfkrkT1*02bJUn+YQts0*xCeka%cGHCN1fjaC*faFtY

come from?

I understand the purpose of app.properties file and I do understand key value assignment. what I don't understand is where this

xOBtdmJZxRcz^jkkyHfkrkT1*02bJUn+YQts0*xCeka%cGHCN1fjaC*faFtY

came from and how it was generated?

Thanks

1 Answer

I asked Chris in our Slack about this. That is the copy of his answer:

"That is a library that can add unique identifiers to be used in a user-facing manner, so that DB identifiers can be hidden But, I never did cover that in the course To use it, you could do the following in your GifServiceImpl..."

@Service
public class GifServiceImpl implements GifService {
  ... 

  @Autowired
  private Hashids hashids;

  ...

  @Override
  public void save(Gif gif, MultipartFile file) {
    try {
      gif.setBytes(file.getBytes());

      // Save first, so that `id` is set
      gifDao.save(gif);

      // Hash the DB `id`
      gif.setHash(hashids.encode(gif.getId()));

      // Save again to persist hash
      gifDao.save(gif);
    } catch (IOException e) {
      System.err.println("Unable to get byte array from uploaded file.");
    }
  }

  ...

"Then you could use the hash in the GifController and associated Thymeleaf templates instead of the id, so that the hash appears in the URL"

Here is the instruction of how to use it, given to me by Chris. Try to play around. On my part I can add the following: HashIds documentation is here: http://hashids.org/java/

Try to read there. I didn't get to that. But it seems to be that documentation and explanation should be pretty good. Hash salt, is the String because of which your unique Hash Ids will be generated, I guess...