kaliber-scala / play-s3

S3 module for Play
MIT License
119 stars 49 forks source link

Getting a bucket with play 2.5 #72

Closed will-r closed 7 years ago

will-r commented 7 years ago

The README example seems not to be up to date with Play 2.5. Calling S3(bucket_name) throws a 'no implicit application in scope' error. Instead I'm calling it like this, which seems to work:

import play.api.Application

class MyController @Inject()(val application: Application) extends Controller {

    val bucket = S3.fromApplication(application).getBucket("my-bucket")

}

Is this broadly right, and if not could you possibly update the example?

Hayena commented 7 years ago

That is one possible approach, another would be is to make the injected application implicit

import play.api.Application

class MyController @Inject()(implicit val application: Application) extends Controller {

    val bucket = S3("my-bucket")

}

or build it with a client and configuration

import play.api.Configuration
import play.api.libs.ws.WSClient

class MyController @Inject()(client: WSClient, configuration: Configuration) extends Controller {

    val bucket = S3.fromConfiguration(client, configuration).getBucket("my-bucket")

}

I will update the README accordingly

EECOLOR commented 7 years ago

Oh, haha @Hayena, did not see your response.

Hayena commented 7 years ago

@EECOLOR that's fine, you made a similar alteration as I was planning ;)

will-r commented 7 years ago

Thank you very much for the quick response. I'm using an injected WSClient and all is well.