@@ -82,7 +82,7 @@ fs_object <- function(fs, client, orig){
82
82
find <- function (filter = ' {}' , options = ' {}' ){
83
83
mongo_gridfs_find(fs , filter , options )
84
84
}
85
- upload <- function (path , name = basename( path ) , content_type = NULL , metadata = NULL ){
85
+ upload <- function (path , name = path , content_type = NULL , metadata = NULL ){
86
86
mongo_gridfs_upload(fs , name , path , content_type , metadata )
87
87
}
88
88
download <- function (name , path = name ){
@@ -130,6 +130,9 @@ mongo_gridfs_find <- function(fs, filter, opts){
130
130
mongo_gridfs_upload <- function (fs , name , path , type , metadata ){
131
131
stopifnot(is.character(name ))
132
132
path <- normalizePath(path , mustWork = TRUE )
133
+ is_dir <- file.info(path )$ isdir
134
+ if (any(is_dir ))
135
+ stop(sprintf(" Upload contains directories, you can only upload files (%s)" , paste(path [is_dir ], collapse = " , " )))
133
136
stopifnot(length(name ) == length(path ))
134
137
id <- rep(NA , length(name ))
135
138
if (is.null(type ))
@@ -147,13 +150,13 @@ mongo_gridfs_upload <- function(fs, name, path, type, metadata){
147
150
mongo_gridfs_download <- function (fs , name , path ){
148
151
stopifnot(is.character(name ))
149
152
path <- normalizePath(path , mustWork = FALSE )
153
+ lapply(path , function (x ){ dir.create(dirname(x ), showWarnings = FALSE , recursive = TRUE )})
150
154
stopifnot(length(name ) == length(path ))
151
- out <- rep( NA , length(name ))
155
+ out <- vector( " list " , length(name ))
152
156
for (i in seq_along(name )){
153
- res <- .Call(R_mongo_gridfs_download , fs , name [i ], path [i ])
154
- out [i ] <- res $ id
157
+ out [[i ]] <- .Call(R_mongo_gridfs_download , fs , name [i ], path [i ])
155
158
}
156
- structure( out , names = name )
159
+ do.call( rbind.data.frame , out )
157
160
}
158
161
159
162
# ' @useDynLib mongolite R_mongo_gridfs_remove
0 commit comments