Skip to content

Instantly share code, notes, and snippets.

🐵

Michał Kreft yomajkel

🐵
  • scalac
  • Barcelona, Spain
View GitHub Profile
@yomajkel
yomajkel / post.scala
Created Sep 24, 2018
the description for this gist
View post.scala
scenario.inject(atOnceUsers(200))
@yomajkel
yomajkel / post.scala
Created Sep 24, 2018
the description for this gist
View post.scala
val scenarioAlpakka = scenario("Upload 1 MB file to S3 with alpakka")
.exec(uploadFileRequest(alpakkaUploadPath, mb1FileName))
val scenarioTmpFile = scenario("Upload 1 MB file to S3 with tmp file")
.exec(uploadFileRequest(tmpFilePath, mb1FileName))
val scenarioTmpMultipart = scenario("Upload 1 MB file to S3 with tmp file and multipart upload")
.exec(uploadFileRequest(tmpFileMultipartPath, mb1FileName))
setUp(
@yomajkel
yomajkel / post.scala
Created Sep 24, 2018
the description for this gist
View post.scala
path("uploadfile") {
withRequestTimeout(20.seconds) {
extractRequestContext { ctx =>
implicit val materializer = ctx.materializer
extractActorSystem { actorSystem =>
fileUpload("file") {
case (metadata, byteSource) =>
@yomajkel
yomajkel / post.scala
Created Sep 24, 2018
the description for this gist
View post.scala
class S3AlpakkaService()(implicit as: ActorSystem, m: Materializer) extends S3Conf {
private val s3Client: S3Client = S3Client(credentialsProvider, region)
def sink(fileInfo: FileInfo): Sink[ByteString, Future[MultipartUploadResult]] = {
val fileName = UUID.randomUUID().toString + ".tmp"
val key = s"alpakka/${fileName}"
s3Client.multipartUpload(bucketName, key)
}
@yomajkel
yomajkel / post.scala
Created Sep 24, 2018
the description for this gist
View post.scala
val tm: TransferManager = TransferManagerBuilder.standard()
.withS3Client(s3Client)
.build()
val upload: Upload = tm.upload(s3Bucket, key, file)
upload.addProgressListener(listener)
@yomajkel
yomajkel / post.scala
Created Sep 24, 2018
the description for this gist
View post.scala
path("temp") {
withRequestTimeout(20.seconds) {
extractExecutionContext { implicit executor =>
storeUploadedFile("file", tempDestination) {
case (metadata, file) =>
val uploadFuture = S3ClientService.upload(file.toPath)
onComplete(uploadFuture) {
case Success(_) => complete(StatusCodes.OK)
case Failure(_) => complete(StatusCodes.FailedDependency)
@yomajkel
yomajkel / post.scala
Created Sep 24, 2018
the description for this gist
View post.scala
case class S3UploaderException(msg: String) extends Exception(msg) with NoStackTrace
object S3ClientService extends S3ClientService
trait S3ClientService extends S3Conf {
private val s3Client: AmazonS3 = new AmazonS3Client(credentialsProvider.getCredentials())
def upload(filePath: Path): Future[String] = {
val fileName = filePath.getFileName().toString()
@yomajkel
yomajkel / post.scala
Created Sep 24, 2018
the description for this gist
View post.scala
val credentials = new BasicAWSCredentials("ACCESS_KEY", "SECRET_KEY")
val s3Client = new AmazonS3Client(credentials)
s3Client.setRegion(Region.getRegion(Regions.EU_WEST_3))
val request = new PutObjectRequest("S3_BUCKET", "s3FileKey", file)
s3Client.putObject(request)
@yomajkel
yomajkel / post.scala
Created Sep 24, 2018
the description for this gist
View post.scala
path("uploadfile") {
withRequestTimeout(20.seconds) {
storeUploadedFile("csv", tempDestination) {
case (metadata, file) =>
// do something with the file and file metadata ...
complete(StatusCodes.OK)
}
}
}
@yomajkel
yomajkel / post.scala
Created Sep 24, 2018
the description for this gist
View post.scala
storeUploadedFile("csv", tempDestination) {
case (metadata, file) =>
// do something with the file and file metadata ...
complete(StatusCodes.OK)
}
You can’t perform that action at this time.