Next.js Discord

Discord Forum

413 - Payload too large

Unanswered
Harlequin posted this in #help-forum
Open in Discord
HarlequinOP
Hello. I'm trying to upload a file to Azure Blob Storage. I'm performing the server action/route handler (tried both) and it always returning 413. I changed next config to 100MB and still the same. Is there any way to get rid of this? I'm just requesting for azure storage to get blob client and then directly using api of it to send array buffer just like that:

const file = value as FileWithPath;
const { name: filename, type: contentType } = file as FileWithPath;
const url = ${getServiceUrl(process.env.BASE_API_PATH)}/files/upload-url${createQueryFromParams({ params: { filename, contentType } })};

const response = await fetch(url, {
headers: {
"Content-Type": "application/json",
Cookie: headers().get("Cookie")!
}
});

const respJson: UseGetFileUploadUrlReturnType = await response.json();
const { storageUrl, sasToken, uniqueName } = respJson;
const blobService = new BlobServiceClient(${storageUrl}/${sasToken});
const containerClient = blobService.getContainerClient(process.env.AZURE_BLOB_SERVICE_CONTAINER_NAME);
const blobClient = containerClient.getBlockBlobClient(uniqueName);

const options = {
blobHTTPHeaders: {
blobContentType: contentType,
blobContentDisposition: attachment; filename=${filename}
}
};

const buffer = await file.arrayBuffer();

try {
await blobClient.uploadData(buffer, options);
} catch (error) {
console.error(error);
}

1 Reply

HarlequinOP
bump