This commit is contained in:
2026-08-28 14:23:18 +07:00
parent fc62098071
commit dee5649254
2 changed files with 288 additions and 10 deletions
+17 -10
View File
@@ -21,7 +21,7 @@ storage = GeneralUtils.GarageStorage(
)
# Safe to run inside concurrent HTTP handlers (e.g., Oxygen.jl, HTTP.jl)
GeneralUtils.put_file(storage, "users-1005.json", "{\"status\": \"active\"}")
downloadUrl = GeneralUtils.put_file(storage, "users1.json", "{\"status\": \"active\"}")
keys = GeneralUtils.list_files(storage)
println("Read back: ", data)
@@ -147,7 +147,7 @@ end
The data to upload.
# Return
- `String`: The file download URL if the upload succeeds.
- `NamedTuple{(:api, :web), Tuple{String, String}}`: The file download URLs if the upload succeeds (`api` for API access, `web` for web access).
- `nothing` if the key contains slashes (upload aborted with warning).
# Notes
@@ -160,7 +160,7 @@ 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
"https://s3-api.yiem.cc/sommpanion-s3/test.json"
(api = "https://s3-api.yiem.cc/sommpanion-s3/test.json", web = "https://s3-web.yiem.cc/sommpanion-s3/test.json")
```
"""
struct put_file
@@ -177,10 +177,13 @@ 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
objURL = "$(pf.storage.config.endpoint)/$(pf.storage.bucket)/$key"
# file download URL using API
api = "$(storage.config.endpoint)/$(storage.bucket)/$key"
return objURL
# file download URL using browser
web = replace(api, "s3-api" => "s3-web")
return (api=api, web=web)
end
""" Upload an object to the Garage S3 bucket.
@@ -194,7 +197,7 @@ end
The data to upload.
# Return
- `String`: The file download URL if the upload succeeds.
- `NamedTuple{(:api, :web), Tuple{String, String}}`: The file download URLs if the upload succeeds (`api` for API access, `web` for web access).
- `nothing` if the key contains slashes (upload aborted with warning).
# Notes
@@ -205,6 +208,7 @@ end
```julia
julia> 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")
```
"""
function put_file(storage::GarageStorage, key::String, data::Union{String, Vector{UInt8}})::String
@@ -218,10 +222,13 @@ 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
objURL = "$(storage.config.endpoint)/$(storage.bucket)/$key"
# file download URL using API
api = "$(storage.config.endpoint)/$(storage.bucket)/$key"
return objURL
# file download URL using browser
web = replace(api, "s3-api" => "s3-web")
return (api=api, web=web)
end
""" Download an object from the Garage S3 bucket.