Skip to content

Commit ef9a2af

Browse files
committed
Switch file upload to proxy through backend instead of SAS URLs
Storage has publicNetworkAccess disabled, so browser cannot PUT directly to blob storage via SAS URLs. Changed frontend to POST files as multipart form data to /api/datasets/{dataset}/upload, which proxies through the backend over the private endpoint.
1 parent 6a8a6ad commit ef9a2af

1 file changed

Lines changed: 27 additions & 21 deletions

File tree

frontend-next/src/lib/api-client.ts

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -447,37 +447,43 @@ class BackendClient {
447447
})
448448
}
449449

450-
// File upload with options - uses SAS URL for production
450+
// File upload with options - proxies through backend to blob storage
451451
async uploadFile(
452452
datasetName: string,
453453
file: File,
454454
options?: UploadOptions
455455
): Promise<{ message: string; id: string }> {
456-
// Get SAS URL for direct blob upload
457-
const uploadInfo = await this.getUploadUrl(file.name, datasetName)
458-
459-
// Determine content type
460-
const contentType = file.type || 'application/octet-stream'
461-
462-
// Upload directly to Azure Blob Storage using SAS URL
463-
const uploadResponse = await fetch(uploadInfo.upload_url, {
464-
method: 'PUT',
465-
headers: {
466-
'x-ms-blob-type': 'BlockBlob',
467-
'Content-Type': contentType,
468-
},
469-
body: file,
456+
await this.initialize()
457+
458+
const formData = new FormData()
459+
formData.append('file', file)
460+
461+
// Build query params for processing options
462+
const params = new URLSearchParams()
463+
if (options) {
464+
if (options.run_ocr !== undefined) params.set('run_ocr', String(options.run_ocr))
465+
if (options.run_gpt_vision !== undefined) params.set('run_gpt_vision', String(options.run_gpt_vision))
466+
if (options.run_summary !== undefined) params.set('run_summary', String(options.run_summary))
467+
if (options.run_evaluation !== undefined) params.set('run_evaluation', String(options.run_evaluation))
468+
}
469+
470+
const queryString = params.toString()
471+
const url = `${this.baseUrl}/api/datasets/${encodeURIComponent(datasetName)}/upload${queryString ? `?${queryString}` : ''}`
472+
473+
const response = await fetch(url, {
474+
method: 'POST',
475+
body: formData,
470476
})
471477

472-
if (!uploadResponse.ok) {
473-
const errorText = await uploadResponse.text().catch(() => '')
474-
throw new Error(`Upload failed: ${uploadResponse.status} ${errorText}`)
478+
if (!response.ok) {
479+
const errorData = await response.json().catch(() => ({}))
480+
throw new Error(errorData.detail || `Upload failed: ${response.status}`)
475481
}
476482

477-
// The blob upload triggers automatic processing via Event Grid
483+
const result = await response.json()
478484
return {
479-
message: `File ${file.name} uploaded successfully to ${datasetName}. Processing will begin automatically.`,
480-
id: uploadInfo.blob_path,
485+
message: result.message || `File ${file.name} uploaded successfully to ${datasetName}. Processing will begin automatically.`,
486+
id: result.document_id || result.blob_path || '',
481487
}
482488
}
483489

0 commit comments

Comments
 (0)