This commit is contained in:
2026-08-28 14:31:26 +07:00
parent dee5649254
commit c1c83eba77
+14 -9
View File
@@ -147,7 +147,7 @@ end
The data to upload.
# Return
- `NamedTuple{(:api, :web), Tuple{String, String}}`: The file download URLs if the upload succeeds (`api` for API access, `web` for web access).
- `String`: The file download URL if the upload succeeds.
- `nothing` if the key contains slashes (upload aborted with warning).
# Notes
@@ -160,13 +160,14 @@ julia> storage1 = GarageStorage("https://s3-api.yiem.cc", "GKb08015", "55114ff94
julia> put_file1 = put_file(storage1)
julia> downloadUrl = put_file1("test.json", "{\"status\": \"active\"}")
Successfully uploaded: test.json
(api = "https://s3-api.yiem.cc/sommpanion-s3/test.json", web = "https://s3-web.yiem.cc/sommpanion-s3/test.json")
"https://s3-api.yiem.cc/sommpanion-s3/test.json"
```
"""
struct put_file
storage::GarageStorage
end
function (pf::put_file)(key::String, data::Union{String, Vector{UInt8}})::String
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')."
@@ -177,7 +178,7 @@ function (pf::put_file)(key::String, data::Union{String, Vector{UInt8}})::String
AWSS3.s3_put(pf.storage.config, pf.storage.bucket, key, data)
println("Successfully uploaded: ", key)
# file download URL using API
# object url
api = "$(storage.config.endpoint)/$(storage.bucket)/$key"
# file download URL using browser
@@ -197,7 +198,7 @@ end
The data to upload.
# Return
- `NamedTuple{(:api, :web), Tuple{String, String}}`: The file download URLs if the upload succeeds (`api` for API access, `web` for web access).
- `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
@@ -206,12 +207,16 @@ end
# Examples
```julia
julia> put_file(storage, "test.json", "{\"status\": \"active\"}")
julia> result = put_file(storage, "test.json", "{\"status\": \"active\"}")
Successfully uploaded: test.json
(api = "https://s3-api.yiem.cc/sommpanion-s3/test.json", web = "https://s3-web.yiem.cc/sommpanion-s3/test.json")
julia> result.api
"https://s3-api.yiem.cc/sommpanion-s3/test.json"
julia> result.web
"https://s3-web.yiem.cc/sommpanion-s3/test.json"
```
"""
function put_file(storage::GarageStorage, key::String, data::Union{String, Vector{UInt8}})::String
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')."
@@ -222,7 +227,7 @@ function put_file(storage::GarageStorage, key::String, data::Union{String, Vecto
AWSS3.s3_put(storage.config, storage.bucket, key, data)
println("Successfully uploaded: ", key)
# file download URL using API
# object url
api = "$(storage.config.endpoint)/$(storage.bucket)/$key"
# file download URL using browser