How to serve json file using ORPC #1052
Answered
by
unnoq
Hugo-Persson
asked this question in
Q&A
-
|
I am trying to create an endpoint to download a JSON file. I have the following code import { z } from "zod";
import { parseDateRangeString } from "../date-utils";
import { getJsonData } from "../exporter";
import { researcherOS } from "../helpers";
export const getStudyManifest = researcherOS
.route({
method: "GET",
summary: "Get study export manifest",
description:
"Returns a downloadable manifest for a study over an optional date range",
})
.handler(async ({ input, context }) => {
const data = await getJsonData(); // Returns a JS object
const file = new File([JSON.stringify([data])], "manifest.json", {
type: "application/json",
});
return {
file,
};
});When I run this I get a file with the name How can I make it download a file |
Beta Was this translation helpful? Give feedback.
Answered by
unnoq
Sep 30, 2025
Replies: 1 comment 1 reply
-
|
This is expected, because you wrap inside an object. Let's try return file directly: return file; |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
unnoq
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is expected, because you wrap inside an object. Let's try return file directly: