Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to pass a path to URL?  RSS feed

 
Mike London
Ranch Hand
Posts: 1441
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to create a web service method that returns the file size of a passed file path.

The problem is that passing the path with multiple "/" (paths) is being misinterpreted as multiple GET parameters rather than a single (path) parameter.

The calling program is dynamically generating the path, but the passed paths will be something like /Users/Mike/Desktop/...../FileName.jpg

Is there any way to send a path like that as one parameter?

TIA

- mike
 
Mike London
Ranch Hand
Posts: 1441
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike London wrote:I am trying to create a web service method that returns the file size of a passed file path.

The problem is that passing the path with multiple "/" (paths) is being misinterpreted as multiple GET parameters rather than a single (path) parameter.

The calling program is dynamically generating the path, but the passed paths will be something like /Users/Mike/Desktop/...../FileName.jpg

Is there any way to send a path like that as one parameter?

TIA

- mike



** SOLVED **

Solution turned out to be to use "%2F".

- mike
 
Paul Clapham
Sheriff
Posts: 22374
42
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In other words, you needed to URL-encode the path so that it would act as a single parameter. Perhaps you just wrote code which would change "/" to "%2F"? If so, you might consider using Java's built-in URLEncoder class, which will take care of that and of any other edge cases you haven't encountered yet.
 
Mike London
Ranch Hand
Posts: 1441
8
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:In other words, you needed to URL-encode the path so that it would act as a single parameter. Perhaps you just wrote code which would change "/" to "%2F"? If so, you might consider using Java's built-in URLEncoder class, which will take care of that and of any other edge cases you haven't encountered yet.


Yep, you got it. BTW, the URLEncode idea was awesome! I had not thought of that and it will save me many hours of frustration. Thank you!!!

-------

URLEncode like the one below that I saw, here: http://alvinalexander.com/blog/post/java/how-encode-java-string-send-web-server-safe-url



(it works without the array and the for loop, too.)

// output --> 'localhost%3A4567%2Ftest%2Ffor%2Fme%2Fthis%2Furlencode'
------------
Thanks for the cow! :)

- mike
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!