Port over Jeremy's fix for slow uploads

ref: https://fizzy.37signals.com/5986089/collections/7/cards/944
This commit is contained in:
Mike Dalessio
2025-07-20 13:19:53 -04:00
parent af1aeca1c6
commit 0a92fc3a16
2 changed files with 47 additions and 0 deletions
@@ -0,0 +1,23 @@
#
# see https://github.com/basecamp/haystack/pull/7862
#
module ActiveStorage
mattr_accessor :service_urls_for_direct_uploads_expire_in, default: 48.hours
end
module ActiveStorageBlobServiceUrlForDirectUploadExpiry
# Override default expires_in to accommodate long upload URL expiry
# without having to lengthen download URL expiry.
#
# Accounts for Cloudflare only proxying slow client uploads once they're
# fully buffered, long after the URL expired.
#
# 48 hours covers a 10GB upload at 0.5Mbps.
def service_url_for_direct_upload(expires_in: ActiveStorage.service_urls_for_direct_uploads_expire_in)
super
end
end
ActiveSupport.on_load :active_storage_blob do
prepend ::ActiveStorageBlobServiceUrlForDirectUploadExpiry
end