I'm trying to store a file which is sent via PUT to a Restlet resource.
The curl statement looks like this:
curl -X PUT "http://localhost:8080/EAIConfig/ri/media" --data-binary img019.png
And this is my resource implementation:
@Override
protected Representation put(Representation entity) throws ResourceException {
try {
InputStream in = entity.getStream();
OutputStream out = new FileOutputStream("/Temp/media-file.png");
IOUtils.copy(in,out);
out.close();
in.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return new EmptyRepresentation();
}
This runns without errors. But the resulting /Temp/media-file.png
does contain the name of the sent file instead of the sent image data.
Any idea how to get the file contents?
I don't think it's a problem in your Restlet code but rather in the way you call it using curl.
You forget the '@' in the parameter --data-binary
. You should use something like that:
curl -X PUT "http://localhost:8080/EAIConfig/ri/media" --data-binary "@img019.png"
I made a try with your code and it works for me. I suppose that you the class IOUtils
from Commons IO.
One small comment. Your method put
needs to be defined as public and with annotation @Put
to be directly called by Restlet ;-)
Hope it helps you, Thierry