slash works
This commit is contained in:
+8
-32
@@ -126,17 +126,12 @@ end
|
||||
|
||||
# Arguments
|
||||
- `key::String`
|
||||
The object key (name) in the bucket. Must not contain slashes (`/`).
|
||||
The object key (name) in the bucket.
|
||||
- `data::Union{String, Vector{UInt8}}`
|
||||
The data to upload.
|
||||
|
||||
# Return
|
||||
- `NamedTuple{(:api, :web)}`: A tuple with `api` and `web` URLs if the upload succeeds.
|
||||
- `nothing` if the key contains slashes (upload aborted with warning).
|
||||
|
||||
# Notes
|
||||
- Slashes in keys are prohibited to prevent S3 listing issues. Use a flat naming
|
||||
convention (e.g., `"users-1002.json"` instead of `"users/1002.json"`).
|
||||
- `NamedTuple{(:api, :web)}`: A tuple with `api` and `web` URLs.
|
||||
|
||||
# Examples
|
||||
```jldoctest
|
||||
@@ -154,14 +149,7 @@ struct put_file
|
||||
storage::GarageStorage
|
||||
end
|
||||
function (pf::put_file)(key::String, data::Union{String, Vector{UInt8}}
|
||||
)::Union{NamedTuple{(:api, :web), Tuple{String, String}}, Nothing}
|
||||
# Check if the key contains a slash (virtual folder character)
|
||||
if occursin('/', key)
|
||||
@warn "Upload aborted! Slashes ('/') are not allowed in keys ('$key') to prevent S3 listing issues. Use a flat naming convention instead (e.g., 'users-1002.json')."
|
||||
return nothing
|
||||
end
|
||||
|
||||
# Proceed if the key is flat
|
||||
)::NamedTuple{(:api, :web), Tuple{String, String}}
|
||||
AWSS3.s3_put(pf.storage.config, pf.storage.bucket, key, data)
|
||||
println("Successfully uploaded: ", key)
|
||||
|
||||
@@ -180,17 +168,12 @@ end
|
||||
- `storage::GarageStorage`
|
||||
The storage client instance.
|
||||
- `key::String`
|
||||
The object key (name) in the bucket. Must not contain slashes (`/`).
|
||||
The object key (name) in the bucket.
|
||||
- `data::Union{String, Vector{UInt8}}`
|
||||
The data to upload.
|
||||
|
||||
# Return
|
||||
- `NamedTuple{(:api, :web)}`: A tuple with `api` and `web` URLs if the upload succeeds.
|
||||
- `nothing` if the key contains slashes (upload aborted with warning).
|
||||
|
||||
# Notes
|
||||
- Slashes in keys are prohibited to prevent S3 listing issues. Use a flat naming
|
||||
convention (e.g., `"users-1002.json"` instead of `"users/1002.json"`).
|
||||
- `NamedTuple{(:api, :web)}`: A tuple with `api` and `web` URLs.
|
||||
|
||||
# Examples
|
||||
```julia
|
||||
@@ -203,14 +186,7 @@ julia> result.web
|
||||
```
|
||||
"""
|
||||
function put_file(storage::GarageStorage, key::String, data::Union{String, Vector{UInt8}}
|
||||
)::Union{NamedTuple{(:api, :web), Tuple{String, String}}, Nothing}
|
||||
# Check if the key contains a slash (virtual folder character)
|
||||
if occursin('/', key)
|
||||
@warn "Upload aborted! Slashes ('/') are not allowed in keys ('$key') to prevent S3 listing issues. Use a flat naming convention instead (e.g., 'users-1002.json')."
|
||||
return nothing
|
||||
end
|
||||
|
||||
# Proceed if the key is flat
|
||||
)::NamedTuple{(:api, :web), Tuple{String, String}}
|
||||
AWSS3.s3_put(storage.config, storage.bucket, key, data)
|
||||
println("Successfully uploaded: ", key)
|
||||
|
||||
@@ -267,8 +243,8 @@ julia> keys = list_files(storage)
|
||||
```
|
||||
"""
|
||||
function list_files(storage::GarageStorage)
|
||||
# Approach 2: s3_list_objects returns a Vector of Dicts with object details
|
||||
objects = AWSS3.s3_list_objects(storage.config, storage.bucket)
|
||||
# Use delimiter="" to get all individual keys (no grouping by "directory")
|
||||
objects = AWSS3.s3_list_objects(storage.config, storage.bucket; delimiter="")
|
||||
return [obj["Key"] for obj in objects]
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user