Replies: 2 comments 3 replies
-
|
I think, in this case you want to use Response, NextResponse is just an extension of Response with some API helpers, but , all you gotta do is pass the data you want to respond with. import type { NextRequest } from "next/server";
import { NextResponse } from "next/server";
export const POST = async (_req: NextRequest) => {
const res = await fetch("https://picsum.photos/200/300");
const blob = await res.blob();
const headers = new Headers();
headers.set("Content-Type", "image/*");
// or just use new Response ❗️
return new NextResponse(blob, { status: 200, statusText: "OK", headers });
};Something like that, for example sends back the image, which you could append to the DOM by doing vanilla JS (or your preferred framework of choice): fetch("/foo", { method: "POST" })
.then((res) => res.blob())
.then((blob) => URL.createObjectURL(blob))
.then((blob) => {
let img = document.createElement("img");
img.src = blob;
document.body.appendChild(img);
}); |
Beta Was this translation helpful? Give feedback.
2 replies
-
|
we need a solution for this |
Beta Was this translation helpful? Give feedback.
1 reply
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.
-
Summary
Is there any way I can return a file as a response using NextResponse?
Additional information
No response
Example
No response
Beta Was this translation helpful? Give feedback.
All reactions