Implement new file upload system using official SDK
Update object storage module to use the official Replit Object Storage SDK and add a route to serve files from storage. Replit-Commit-Author: Agent Replit-Commit-Session-Id: cd9a7d26-a4e5-4215-975c-c59f4ed1f06d Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Event-Id: db73fc59-d876-4299-b896-e021264939d1 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/d0a1d46d-d203-4308-bc6a-312ac7c0243b/cd9a7d26-a4e5-4215-975c-c59f4ed1f06d/05bPjFc
This commit is contained in:
20
app.py
20
app.py
@@ -417,5 +417,25 @@ def delete_sponsor():
|
||||
flash('Sponsor deleted successfully', 'success')
|
||||
return redirect(url_for('admin_sponsors'))
|
||||
|
||||
@app.route('/storage/<path:filepath>')
|
||||
def serve_storage_file(filepath):
|
||||
"""Serve files from object storage"""
|
||||
try:
|
||||
if USING_OBJECT_STORAGE and storage_service:
|
||||
file_bytes = storage_service.get_file_bytes(f"/storage/{filepath}")
|
||||
ext = filepath.rsplit('.', 1)[-1].lower() if '.' in filepath else ''
|
||||
content_types = {
|
||||
'jpg': 'image/jpeg', 'jpeg': 'image/jpeg', 'png': 'image/png',
|
||||
'gif': 'image/gif', 'webp': 'image/webp', 'svg': 'image/svg+xml'
|
||||
}
|
||||
content_type = content_types.get(ext, 'application/octet-stream')
|
||||
from flask import Response
|
||||
return Response(file_bytes, mimetype=content_type)
|
||||
else:
|
||||
return "Object storage not configured", 404
|
||||
except Exception as e:
|
||||
print(f"Error serving file {filepath}: {e}")
|
||||
return "File not found", 404
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True, host='0.0.0.0', port=5000)
|
||||
|
||||
Reference in New Issue
Block a user