cloudyr / aws.s3

Amazon Simple Storage Service (S3) API Client
https://cloud.r-project.org/package=aws.s3
381 stars 148 forks source link

s3save with region parameter for IBM S3 compatibility #388

Open jcbastiani opened 3 years ago

jcbastiani commented 3 years ago

Before filing an issue, please make sure you are using the latest development version which you can install using install.packages("aws.s3",repo="https://rforge.net") (see README) since the issue may have been fixed already. Also search existing issues first to avoid duplicates.

Please specify whether your issue is about:

If you are reporting (1) a bug or (2) a question about code, please supply:

Put your code here:

## load package
library("aws.s3")

## code goes here
s3save(mydf,bucket="mybucket",object="my.Rdata",region="")

## session info for your system
sessionInfo()

IBM S3 storage requires region="" option, but since this option is not in the function options, it fails.

I did quick fix as following:

s3save <- function (..., object, bucket, region = NULL, envir = parent.frame(), opts = NULL) 
{
  tmp <- tempfile(fileext = ".rdata")
  on.exit(unlink(tmp))
  save(..., file = tmp, envir = envir)
  if (missing(bucket)) {
    bucket <- get_bucketname(object)
  }
  object <- get_objectkey(object)
  if (is.null(opts)) {
    r <- put_object(file = tmp, bucket = bucket, object = object, region = region)
  }
  else {
    r <- do.call("put_object", c(list(file = tmp, bucket = bucket, region = region,
                                      object = object), opts))
  }
  return(invisible(r))
}

That works for me.