How to upload a file from the client or from postman to the server? #24826
Replies: 1 comment 2 replies
-
According to the oak documentation the |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
What is the best way to be able to send a file to the database? I see most of people are storing tempFiles in the server and then sending it to the DB. I am trying to achieve the first piece which is the temporary storage, but I am getting errors. This is my server.ts:
`// server.ts
import { Application, Router } from "https://deno.land/x/oak/mod.ts";
import { ensureDir } from "https://deno.land/std/fs/mod.ts";
import { join } from "https://deno.land/std/path/mod.ts";
import { crypto } from "https://deno.land/std/crypto/mod.ts";
const app = new Application();
const router = new Router();
const uploadDir = './uploads';
await ensureDir(uploadDir);
router.post('/upload', async (context) => {
if (context.request.hasBody) {
const body = await context.request.body({ type: 'form-data' }).value;
const rspBody = { fields: 0, files: 0 };
} else {
context.response.status = 400;
context.response.body = { error: "No file uploaded" };
}
});
app.use(router.routes());
app.use(router.allowedMethods());
console.log("Server is running on port 8000");
await app.listen({ port: 8000 });`
But I am getting the error i the line 15, it says in the .request.body( ->
This expression is not callable.
Type 'Body' has no call signatures.deno-ts(2349)
(property) Request.body: Body
An interface to access the body of the request. This provides an API that aligned to the Fetch Request API, but in a dedicated API.
No quick fixes available
Screenshot attached
Beta Was this translation helpful? Give feedback.
All reactions