If I create a thread and upload an image the img src is set to my S3_CDN_URL. If I upload a zip file the URL is at /uploads and redirect directly to my bucket instead of using the S3_CDN_URL. I do not have DISCOURSE_CDN_URL set - the guide indicate it doesn’t affect this issue.
Thank you.
I’ve assigned the job to some local friend of mine. He is looking into it.
Though on your asking I selected this option just now. Use CDN URL for all the files uploaded to s3 instead of only for images.
But there seems to be some other problem. He has shifted s3 storage to local server. Now many of my old posts, which if had 10 photos, around half are displaying and other half not. (example of one such topic)
He would work on resolving this, coming weekend.
Earlier, before asking him, I naively selected the option to have all images included in my backups, then restored that backup thinking that it’d restore the images to local server, thinking that this would be enough to move all my images from s3 to local.
But this is not so simple (as I’m finding on many related topics on meta).
I think that the missing images on that post are because the Upload record doesn’t exist, so you’ll need to do something to get that image back. I could be wrong.
If I’m right, here’s how I solved what I think was a similar problem before. I’m offering no free support beyond this script.
def process_uploads
begin
# Read the list of filenames
filenames = File.readlines('/shared/uploads/allfiles.txt').map(&:strip)
count = 0
filenames.each do |filename|
# Prepend /shared to the filename
filename.gsub!(/\.\//,"")
full_path = File.join('/shared/uploads/default/original/', filename)
begin
# Check if path exists and is a regular file (not a directory)
count += 1
if File.exist?(full_path) && File.file?(full_path)
# Open the file
File.open(full_path, 'r') do |tempfile|
# Create upload using the specified parameters
u = UploadCreator.new(tempfile, 'imported', {}).create_for(-1)
puts "#{count} -- #{u.id}: #{u.url}"
end
else
puts "Warning: Path not found or is not a regular file: #{full_path}"
end
rescue => e
puts "Error processing file #{full_path}: #{e.message}"
# Continue with next file even if current one fails
next
end
end
rescue Errno::ENOENT
puts "Error: Could not find files.txt"
rescue => e
puts "Error reading files.txt: #{e.message}"
end
end
# Execute the processing
process_uploads;