Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add streaming API to model upload #1

Open
brettlangdon opened this issue Jan 29, 2014 · 2 comments
Open

Add streaming API to model upload #1

brettlangdon opened this issue Jan 29, 2014 · 2 comments

Comments

@brettlangdon
Copy link
Contributor

"If I may presume to make one suggestion going forward, it would be that you consider adding a streaming API for uploading the models themselves. For performance reasons, I think that this is absolutely essential, especially when you are consuming larger models produced by external processes or redirected from disk. Globbing an entire mesh into memory for each upload can quickly consume all of the limited heap available to a node process and cause server crashes. Streams also implement back pressure which optimally handles performance and routing problems for throttling. I half-heartedly tried to get something like this to work in the older SOAP api, but was unsuccessful mostly due to the undue hassle of inserting a stream into the middle of a SOAP request and the general crappiness of the current options for handling SOAP/XML in node. However with the current REST system, I believe that this should be much easier to implement and that it really ought to be exposed as the default method for uploading."

From @mikolalysenko via e-mail.

@bdickason
Copy link

+1 for this. I was running into a similar problem when writing my test client.

@mikolalysenko
Copy link

Thanks for the mention. From my experience working on the previous client, (and from hacking around in node in general) I think that streaming should be the default/main method for all of the API methods that push big chunks of data. Like:

  • addModel
  • getModelFile
  • addModelFile
  • getModelPhoto
  • addModelPhoto

Regarding the addModel method, maybe you could do something like this:

var uploadStream = shapewaysClient.addModel({
   filename: "mymodel.stl",
   //User specified data goes here
})
myModelData.pipe(uploadStream)
uploadStream.pipe(toJSON(function(err, result) {
  if(e) {
     console.log("upload failed:", err)
  }
  console.log("upload succeeded, result:", result)
})

Or for a simpler example where you just fire-and-forget the response, here is a sketch of how a 1-line streaming photo upload could work:

myPhotoStream.pipe(shapewaysClient.addModelPhoto(myModelId, { /* optional params */ })

Again, addModelFile could do basically the same thing. Streams would also work for downloads too. For example,

shapewaysClient.getModelFile(myModelId).pipe(fs.createWriteStream("download.stl"))

Anyway, what do you think about this proposal?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants