This commit is contained in:
2026-08-28 08:28:35 +07:00
parent 27703c3324
commit c4741140f5
+15 -10
View File
@@ -168,7 +168,7 @@ Successfully uploaded: test.json
struct put_file struct put_file
storage::GarageStorage storage::GarageStorage
end end
function (pf::put_file)(key::String, data::Union{String, Vector{UInt8}}) function (pf::put_file)(key::String, data::Union{String, Vector{UInt8}})::String
# Check if the key contains a slash (virtual folder character) # Check if the key contains a slash (virtual folder character)
if occursin('/', key) 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')." @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')."
@@ -209,16 +209,21 @@ julia> put_file(storage, "test.json", "{\"status\": \"active\"}")
Successfully uploaded: test.json Successfully uploaded: test.json
``` ```
""" """
function put_file(storage::GarageStorage, key::String, data::Union{String, Vector{UInt8}}) function put_file(storage::GarageStorage, key::String, data::Union{String, Vector{UInt8}})::String
# Check if the key contains a slash (virtual folder character) # Check if the key contains a slash (virtual folder character)
if occursin('/', key) 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')." @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 return nothing
end end
# Proceed if the key is flat # Proceed if the key is flat
s3_put(storage.config, storage.bucket, key, data) s3_put(storage.config, storage.bucket, key, data)
println("Successfully uploaded: ", key) println("Successfully uploaded: ", key)
# file download URL
objURL = "$(pf.storage.config.endpoint)/$(pf.storage.bucket)/$key"
return objURL
end end
""" Download an object from the Garage S3 bucket. """ Download an object from the Garage S3 bucket.