AngularJS + Ratpack File Upload

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

AngularJS + Ratpack File Upload

seanwalsh
This post was updated on .
I threw together an example of using AngularJS and Ratpack to upload and display images:

https://github.com/s992/angular-ratpack-upload

I'm planning on writing a blog post on it this weekend (or sometime this week, depending on how much I procrastinate!), but I figured I'd share the code now.

If anyone has any comments/criticisms, I'd love to hear them!

EDIT: If anyone comes across this and is interested in the blog post, I ended up with a two part series:

http://swalsh.org/blog/2014/09/16/file-uploads-with-angularjs-and-ratpack-part-1/
http://swalsh.org/blog/2014/09/17/file-uploads-with-angularjs-and-ratpack-part-2/
==============================
http://swalsh.org
https://twitter.com/THEseanwalsh
Reply | Threaded
Open this post in threaded view
|

Re: AngularJS + Ratpack File Upload

Luke Daley
Administrator
Hi,

Thanks for sharing. I forked the project and made some edits: https://github.com/alkemist/angular-ratpack-upload

Sorry about the whitespace changes; it was just easier. I imagine you can just pick out the bits of code that you want to use.


Reply | Threaded
Open this post in threaded view
|

Re: AngularJS + Ratpack File Upload

seanwalsh
Wow, that's awesome! Thanks, Luke, totally above and beyond what I was expecting when I posted this. I understand most of your changes, but I do have a couple of questions.

I placed the config options in ratpack.properties because I didn't know where else to stick them. It didn't feel like the correct choice at the time and your changes confirm that it wasn't. Having the config in ratpack.groovy works fine in this case, but thinking ahead to a (hypothetical) real project with multiple developers working on it, I don't know how I feel about having config options there. Is there anything built in for arbitrary config files, or is that more of a "roll your own" kind of thing?

This next question probably stems from my lack of Guice knowledge, so please bear with me. What difference (if any) is there between using a module to bind a class to Scopes.SINGLETON and just annotating it with @Singleton?  I had assumed I needed a module to take advantage of Guice, but I can see now that that's not the case. If I had two classes in the image package (e.g. ImageService and ImageResizer), would it make sense to have an ImageModule or would the @Singleton annotation still be sufficient?

Thanks again for the review and the edits!
==============================
http://swalsh.org
https://twitter.com/THEseanwalsh
Reply | Threaded
Open this post in threaded view
|

Re: AngularJS + Ratpack File Upload

Luke Daley
Administrator
Hi Sean,

You’re welcome.

I probably would use the launch config for this, as you can override via system properties in production and so forth. Not much would really change with the way the app was coded, you’d just move those vars “down” so you could read the initial values from the app. It would probably still make sense to do everything relative to the base dir as this is relative though. We are currently working on a better configuration story: https://github.com/ratpack/ratpack/issues/212

re Guice: In this case, there’s no difference. I changed the app to use what’s called a just-in-time (JIT) binding in Guice. It works in this case because the bindings for ImageService are very simple. Modules become useful for more complex bindings (e.g. you want to bind an implementation to an interface). 

Ratpack only uses Guice JIT bindings for the registry returned by `Chain.getRegistry()`, which is what prefix(String, Closure) uses. This means that this will work…

<code>
prefix(“images”) { ImageService imageService ->

}
</code>

But this won’t …

<code>
prefix(“images”) {
  get { ImageService imageService ->

  }
}
</code>

That can be another reason not to use JIT bindings.
Reply | Threaded
Open this post in threaded view
|

Re: AngularJS + Ratpack File Upload

seanwalsh
Great info, thanks again. I'm in the process of integrating your changes now - guess I'll be missing my "this weekend" goal for my blog post. :)
==============================
http://swalsh.org
https://twitter.com/THEseanwalsh