Error on retrieving the uploaded files with auto-generated names to Sling by cURL

StackOverflow https://stackoverflow.com/questions/23342850

  •  11-07-2023
  •  | 
  •  

Question

I want to upload some binary files to Sling with cURL and I want Sling to automatically generate the file names.

From what I have read, I must use POST command and set the destination to a folder:

`curl -X POST -d im2.png -u admin:admin http://192.168.2.130:8080/content/*`

In the returned html, everything seems OK: Status=201 and content created at /content/9_1398511015890 Now, when I try to get the file by typing

curl -X GET -u admin:admin http://192.168.2.130:8080/content/9_1398511015890

an empty result is returned (302 Found, Contents-Length=0) and if I try with a browser, it redirects to ../9_1398511015890/ and generates a 403 error.

This also happen when I set a file name in the POST request. I now I can use -T option, but then I cannot ask the Sling to generate file names for me. Any help is appreciated.

Was it helpful?

Solution

I'd be happy to be proven wrong but AFAIK the default Sling POST servlet does not use the data that you pass with -d in this case.

As you indicate you should use the PUT method instead (curl -T), which does not generate node names automatically.

A workaround, if that's acceptable, would be to first create (using a POST with no parameters) a folder with an autogenerated name, and then PUT your file in that folder.

If the extra path component is not ok, I'm afraid you'll have to create your own custom POST or PUT servlet for that...and maybe contribute that feature to Apache Sling ;-)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top