Merge pull request #640 from SuanmoSuanyangTechnology/fix/features_028
fix(file)
This commit is contained in:
@@ -685,18 +685,14 @@ async def permanent_download_file(
|
|||||||
media_type=file_metadata.content_type or "application/octet-stream"
|
media_type=file_metadata.content_type or "application/octet-stream"
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
# For remote storage, use permanent public URL (requires bucket public read)
|
# For remote storage, redirect to presigned URL with long expiration
|
||||||
try:
|
try:
|
||||||
permanent_url = await storage.get_permanent_url(file_key)
|
# Use a very long expiration (7 days max for most cloud providers)
|
||||||
if permanent_url:
|
|
||||||
api_logger.info(f"Redirecting to permanent public URL: file_key={file_key}")
|
|
||||||
return RedirectResponse(url=permanent_url, status_code=status.HTTP_302_FOUND)
|
|
||||||
# Fallback: long-lived presigned URL
|
|
||||||
presigned_url = await storage_service.get_file_url(file_key, expires=604800)
|
presigned_url = await storage_service.get_file_url(file_key, expires=604800)
|
||||||
presigned_url = _match_scheme(request, presigned_url)
|
presigned_url = _match_scheme(request, presigned_url)
|
||||||
return RedirectResponse(url=presigned_url, status_code=status.HTTP_302_FOUND)
|
return RedirectResponse(url=presigned_url, status_code=status.HTTP_302_FOUND)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
api_logger.error(f"Failed to get permanent URL: {e}")
|
api_logger.error(f"Failed to get presigned URL: {e}")
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||||
detail=f"Failed to retrieve file: {str(e)}"
|
detail=f"Failed to retrieve file: {str(e)}"
|
||||||
|
|||||||
Reference in New Issue
Block a user