1

I have a requirement to send the folder details in the URL for POST method, some thing like this http:///{directory}/{filename}

I am using Spring API to create the service. Using @PathVariables to two variables in the URI.

Problem : Directory can have "/" slashes in it. Now how can I create my API, please help me.

Kumar
  • 1,106
  • 4
  • 15
  • 33
  • 2
    Why do you wanna send this information using URL? What if you send this information as a part of POST payload? – asg Jan 20 '17 at 17:56
  • 1
    You can create or ask others to create payload like this. { "directoryName" : "MyDir", "fileName" : "Its my new file" } – asg Jan 20 '17 at 18:01
  • 1
    This will give you some flexibility if you would like to extend/add some details to your REST API. – asg Jan 20 '17 at 18:02
  • 1
    And your url will be: POST : http://{your web context}/files – asg Jan 20 '17 at 18:02
  • @asg I try that and used JSONUtil to unMarshal that, but that is giving the problem. It is throwing an Exception saying "/" slash is not allowed. – Kumar Jan 20 '17 at 18:03
  • 1
    Then you may want to ask that specific question with your exception, jars used etc. – asg Jan 20 '17 at 18:06
  • Possible duplicate of http://stackoverflow.com/questions/12516969/spring-mvc-getting-pathvariables-containing-dots-and-slashes – Jimmy T. Jan 21 '17 at 09:23
  • I managed it with the JSON input data. – Kumar Feb 17 '17 at 13:45

1 Answers1

0
POST http://example.com/api/files/path/to/my/file/filename

Stick a controller on /api/files. Scrape the URL starting after /files. Use that to locate the file.

P.S. This has the potential to be a Very Bad Idea. Make sure you secure the controller to only expose those parts of your filesystem you don't mind random internet strangers to be able to operate on.

Eric Stein
  • 13,209
  • 3
  • 37
  • 52
  • I think that might live some security issue. I try to remove those path variables and convert that as JSON object , but JSONUtil.unMarshall throwing an error because value have "/" slash in it – Kumar Jan 20 '17 at 17:47