Replies: 4 comments 6 replies
|
push |
0 replies
|
did you find any solution ? |
1 reply
|
the solution : route.ts : // working fine
import { NextResponse } from 'next/server';
import { Directus } from '@directus/sdk';
import { Blob } from 'node:buffer';
import FormData from 'form-data';
export async function POST(request: Request) {
// Get Directus configuration
const token: string = process.env.DIRECTUS_JOB_TOKEN!;
const url: string = process.env.DIRECTUS_URL!;
const directus = new Directus<any>(url);
await directus.auth.static(token).then(res => {
console.log("res",res)
});
// Get formData from request
const formData = await request.formData();
// Get file from formData
const file = formData.get('file');
if (file instanceof Blob) {
// Convert file to stream
const stream = file.stream();
// Convert stream to buffer
const chunks = [];
for await (const chunk of stream) {
chunks.push(chunk);
}
const buffer = Buffer.concat(chunks);
// Make a new FormData
const directusFormData = new FormData();
directusFormData.append('folder', '887b5198-6b28-4289-8117-87deb4df5e71');
directusFormData.append("file", buffer, file.name);
try {
// const response = await directus.files.createOne(directusFormData);
const response = await directus.files.createOne(directusFormData).then(async response =>{ return response} );
console.log("response", response);
return NextResponse.json({ "message": "Hello, Next.js!" });
} catch (error) {
console.log(error);
return NextResponse.json({ "message": "Error" });
}
}
}
|
3 replies
|
I didn't understand your question. Could you please elaborate?
…On Sat, Jun 3, 2023, 4:54 AM Muhammad Ahmad ***@***.***> wrote:
can you please share how you done this with s3
—
Reply to this email directly, view it on GitHub
<#46891 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AL7PSPTIMD3WJQ7EHNLPOHLXJJVKRANCNFSM6AAAAAAV2EKYAA>
.
You are receiving this because you commented.Message ID: <vercel/next.
***@***.***>
|
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Summary
Im trying to create a
POSTendpoint wich extracts files from a form and uploads it f.e. to S3:Error message:
I already found an answer regarding the old "Api routes" wich says to set
bodyParser=false: https://stackoverflow.com/a/73991222/10739610I cannot find to set sth similar in he new route handlers and just tried to use the same
const config...here... without success.Implementation:
Additional information
No response
Example
No response
All reactions