(options: UploadFileOptions)
| 90 | * Upload a file to the configured storage provider with context-aware configuration |
| 91 | */ |
| 92 | export async function uploadFile(options: UploadFileOptions): Promise<FileInfo> { |
| 93 | const { file, fileName, contentType, context, preserveKey, customKey, metadata } = options |
| 94 | |
| 95 | logger.info(`Uploading file to ${context} storage: ${fileName}`) |
| 96 | |
| 97 | const config = getStorageConfig(context) |
| 98 | |
| 99 | const keyToUse = customKey || fileName |
| 100 | |
| 101 | if (USE_BLOB_STORAGE) { |
| 102 | const { uploadToBlob } = await import('@/lib/uploads/providers/blob/client') |
| 103 | const uploadResult = await uploadToBlob( |
| 104 | file, |
| 105 | keyToUse, |
| 106 | contentType, |
| 107 | createBlobConfig(config), |
| 108 | file.length, |
| 109 | preserveKey, |
| 110 | metadata |
| 111 | ) |
| 112 | |
| 113 | if (metadata) { |
| 114 | await insertFileMetadataHelper( |
| 115 | uploadResult.key, |
| 116 | metadata, |
| 117 | context, |
| 118 | fileName, |
| 119 | contentType, |
| 120 | file.length |
| 121 | ) |
| 122 | } |
| 123 | |
| 124 | return uploadResult |
| 125 | } |
| 126 | |
| 127 | if (USE_S3_STORAGE) { |
| 128 | const { uploadToS3 } = await import('@/lib/uploads/providers/s3/client') |
| 129 | const uploadResult = await uploadToS3( |
| 130 | file, |
| 131 | keyToUse, |
| 132 | contentType, |
| 133 | createS3Config(config), |
| 134 | file.length, |
| 135 | preserveKey, |
| 136 | metadata |
| 137 | ) |
| 138 | |
| 139 | if (metadata) { |
| 140 | await insertFileMetadataHelper( |
| 141 | uploadResult.key, |
| 142 | metadata, |
| 143 | context, |
| 144 | fileName, |
| 145 | contentType, |
| 146 | file.length |
| 147 | ) |
| 148 | } |
| 149 |
no test coverage detected