22
$\begingroup$

I have a Mathematica program that modifies images that I would like to make available for other people to use through the web. The input is only one parameter. So, for example, I could run it as a command line action which takes an argument, then returns the image which pops up as a download from the web page.

What is a way to structure this functionality?

So, just to be clear I could have a function like

makeDecloudedImage[ image_, x_ : 0 < RationalQ < 1 ]

or whatever which returns a PNG. I want to know how to hook up a function like this (or another equivalent mechanism) to a web page. In one approach Mathematica itself would run as the web server; another idea would be to have the web server call Mathematica somehow (through shared memory maybe?). This would probably be running on a Linux box.

One approach might be to use CGI. The web page makes a CGI call to Mathematica, executes the function to create the file, returns the path to the file and quits. The problem with this approach is that the whole program has to load which takes a relatively long time. It would be better to have mathematica in memory and just call it like a server somehow from the web server OR have Mathematica be the web server itself.

$\endgroup$
  • 3
    $\begingroup$ Have you seen this? youtube.com/watch?v=dgUiIe-Vz6g It is an interesting video...I expected the functionality will be available in M11...but it did not :( $\endgroup$ – PlatoManiac Aug 12 '16 at 20:20
  • $\begingroup$ related: (66131), (27785). $\endgroup$ – WReach Aug 13 '16 at 3:42
  • $\begingroup$ related: (111749) $\endgroup$ – C. E. Aug 13 '16 at 9:53
  • 2
    $\begingroup$ The obvious answer is: create an instant API in Wolfram Cloud. $\endgroup$ – C. E. Aug 13 '16 at 10:01
  • 1
    $\begingroup$ @PlatoManiac it does exist. It's just under HTTPHandling`StartWebServer. If you just touch that symbol it'll load the necessary package. $\endgroup$ – b3m2a1 May 22 '17 at 18:47
4
$\begingroup$

I use a ProcessObject wrapper to python's SimpleHTTPServer. In many way it's similar to this. The code is like 25 lines long or something. The basic function is something I called PySimpleServerOpen which starts the server in a page directory and opens it. The implementation is here.

It's basically a toy, but I make good use of it. I test doc page changes and preview my website with it.

Of course, as C. E. mentions, the simple thing is to make an APIFunction. Unless you have massive traffic to it you probably won't run out of cloud credits as they seem to accumulate. I'm currently up to >4500 on one account, >5500 on another, and have a few other accounts I don't really use much. I move between these using a key-chain function I called KeyChainConnect so it's not even like having multiple accounts causes me any trouble.

If you're really worried about running out of credits, make like 6 accounts now, deploy the same APIFunction to all of them, then put an HTTPRedirect page at a consistent URI and if you run out of credits on one account, just change that page to route to a new account. It's the cheap-skates way to use the cloud.

Of course, it's highly unlikely you'll run out of credits in the first place, so I wouldn't stress about it.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.