@arolariu/website / lib/actions/invoices/createInvoiceScan / createInvoiceScan
Function: createInvoiceScan()
createInvoiceScan(
input):ServerActionOutputType
Defined in: lib/actions/invoices/createInvoiceScan.ts:107
Uploads an invoice scan to Azure Blob Storage.
Parameters
input
ServerActionInputType
Upload parameters
Returns
ServerActionOutputType
Object with HTTP status and blob URL
Remarks
Execution Context: Server-side only (Next.js server action).
Authentication: Uses Azure DefaultAzureCredential which supports:
- Managed Identity (production on Azure)
- Azure CLI credentials (local development)
- Environment variables (CI/CD)
Side Effects:
- Creates blob in Azure Storage "invoices" container
- Emits OpenTelemetry span for tracing
- Sets blob metadata including size and content type
Performance:
- Base64 decoding happens server-side
- Direct upload to Azure (no intermediate storage)
Throws
When Azure authentication fails
Throws
When blob upload fails
Example
import {createInvoiceScan} from "@/lib/actions/invoices/createInvoiceScan";
import {v4 as uuidv4} from "uuid";
// Convert file to base64 (client-side)
const base64 = await fileToBase64(file);
// Upload to Azure (server action)
const {status, blobUrl} = await createInvoiceScan({
base64Data: base64,
blobName: `${uuidv4()}.jpg`,
metadata: { uploadedBy: "user-123" }
});
if (status === 201) {
console.log("Uploaded to:", blobUrl);
}
See
createInvoice for using the blob URL in invoice creation