Sangram Anand
Sangram Anand

Reputation: 10850

Slugify the url in java

We upload files to Amazon AWS S3 server and use the file url in java class files to provide the functionality of downloading files.

if i upload the file as "Test Automated Report Sheet.pdf" (containing spaces between words) then the url for that is

https://s3.amazonaws.com/cdn.generalsentiment.com/MVR/reports/Test+Automated+Report+Sheet1.pdf

I am getting ArrayIndex Out of bound exception as the url contains '+' sign, therefore am replacing the '+' sign again with whitespace. here is the code for doing that. I am using

String reportURL = mediaValueReport.getReportFileURL().replace('+', ' ');

Is this approach fine or can i write it a more optimal way.

Upvotes: 0

Views: 283

Answers (1)

Shahzeb
Shahzeb

Reputation: 4785

There is no need to do this manually . It is a standard for encoding and decoding of URL.

There are many helper liberaies that you can use e.g URLDecoder

Upvotes: 2

Related Questions