0

File can not open when URL contains is % like following example.

File name: work12%Complete.jpg

URL: http://.../work12%Complete.jpg

I have try following option for this, But using this option set %25 instead of % , So file can not open in UIimage.

var strUrl:String! = documentDetails.value(forKey: "thumbURL") as! String
strUrl = strUrl.addingPercentEncoding(withAllowedCharacters:NSCharacterSet.urlQueryAllowed);
print(strUrl!);
imgView.setImageWith(URL(string: strUrl)!, placeholderImage: UIImage(named : "DefaultImage"));

Output: http://.../work12%25Complete.jpg

if pass value directly in url like follow then app crash when UIimage set this url.

imgView.setImageWith(URL(string: "http://.../work12%Complete.jpg")!, placeholderImage: UIImage(named : "DefaultImage"));

Note:- If i have removed % from file name then created url like http://.../work12Complete.jpg, it's working fine, But i want to solution for file name contains is %.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
AtulParmar
  • 4,358
  • 1
  • 24
  • 45
  • is there any possibility that your file name can contain % sign? – A K M Saleh Sultan Apr 10 '17 at 14:44
  • yes rmaddy, i have found file name and url contain % sign from webservice, and i want to handle this. – AtulParmar Apr 10 '17 at 14:48
  • Since a file name or url can contain % sign and replacing with this % sign with + (plus sign) can work, then add a one line of code where you can replace any % sign available in a url with + sign. OR just ignore % with empty. Like below - yourURL.replacingOccurrences(of: "%", with: "") – A K M Saleh Sultan Apr 10 '17 at 14:54
  • @SalehSultan, I have try with rename on file replace + from % it's working fine, but in server hundred or thousand of file which is contain is %, or it may by put again new file which contain %, So i want to solution for % . – AtulParmar Apr 10 '17 at 14:58
  • if i put your solution "replace any % sign available in a url with + sign. OR just ignore % with empty." so file can not found from server. for example "http://.../work12%Complete.jpg" file exist in server but "http://.../work12+Complete.jpg" file can not found from server. – AtulParmar Apr 10 '17 at 15:01
  • Confusing. you just said replacing with % sign with + works fine for you. But again said in your last comment 'http://../work12+Complete.jpg" file can not found from server'. Can you please elaborate more clearly, what exactly is your question? – A K M Saleh Sultan Apr 10 '17 at 15:05
  • try two scenario: 1) try with rename 1 file from server replace % to + No any change from my side (ios code) just display image from url, so that one file display properly, But in this case i can not change rename each and every file. 2) if no any change from server side keep file name as it is with % and only change from my side(ios code) replace % to + then this kind of file not found from server, because of in server, file name contains % and i try to display with + so it is not possible. – AtulParmar Apr 11 '17 at 05:03
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/141436/discussion-between-saleh-sultan-and-atulparmar). – A K M Saleh Sultan Apr 11 '17 at 13:21

0 Answers0