Search code examples
ropencpu

Send an image file using opencpu for processing


I am an R and OpenCpu newbie. I have been able to create and deploy a simple R package with a function, and make a REST call to the function with curl get a json response.

I am using R 3.1.2 64 bit on Windows 7.

I now want to send an image file (say jpg or png) to an R function, process it and send back a response as text/json.

Is this possible with opencpu? What format and content-type should I be using?

I want to do something like:

curl -v http://server:port/ocpu/library/mylibrary/R/myimagefunc/<format?> -H "Content-Type: <content-type?>" <some_file.png>

This REST url would be embedded in a web application providing a file upload capability to the user.

------ Edit ------

aboutimage <- function(imageobj) {
    require(RProtoBuf)
    require(EBImage)
    img <- readImage(imageobj)
    nf <- numberOfFrames(img)
    print(nf)
    return(nf)
}

Thanks.


Solution

  • You can upload files using regular multipart post. Try this:

    curl -v http://server:port/ocpu/library/mylibrary/R/myimagefunc -F "[email protected]"
    

    When POST-ing a file upload, the opencpu server will copy the file to the working directory and pass the name of the file as the argument to your function call. So in this case it executes:

    myimagefunc(imageobj = "yourfile.png")