deligenius / multiparser

multipart/form-data parser for Deno servers
28 stars 7 forks source link

Can't have multiparser with upload #3

Closed osorito closed 4 years ago

osorito commented 4 years ago

If you send a form and use multiparser, it works great. If you send files or in my case an image the image is visible on the form but you can't store said files on the server. Thats where upload comes in. If i use upload by itself the image gets stored on the server.

Let me show you my route

router.post('/feed/post',upload('images', ['jpg','png','jpeg'], 20000000, 10000000, true, false, true),createPost);

The upload comes from this url import { upload, preUploadValidate} from "https://deno.land/x/upload_middleware_for_oak_framework/mod.ts";

If I use upload alone, I can save the image or file on the server on the specified folder. If I just use multiparse without upload middleware I can see the entire form information.

The problem is that I can't use them both. `export const createPost = async (ctx:any)=>{ try{

    const data = await ctx.request.body();
    console.log(JSON.stringify(data));
    const form = JSON.stringify(await multiParser(ctx.request.serverRequest));
    const body = JSON.parse(form);
    console.log(body.imageUrl.filename);
    console.log(body.title);`

This is the error I get. Listening on: http://localhost:5000 OPTIONS http://localhost:5000/feed/post - Wed Jul 15 2020 12:35:39 GMT-0400 (EDT) {"type":"form-data","value":{}} POST http://localhost:5000/feed/post - Wed Jul 15 2020 12:35:39 GMT-0400 (EDT) error: Uncaught UnexpectedEof: throw new Deno.errors.UnexpectedEof(); ^ at MultipartReader.nextPart (multipart.ts:371:15) at async MultipartReader.readForm (multipart.ts:286:17) at async multiParser.ts:23:24 [denon] app crashed - waiting for file changes before starting ...

gjuoun commented 4 years ago

Multiparse is supposed to work alone.

When the request body is read by another middleware. The body reader would be nothing after. So in your case, the request's body is consumed by upload() middleware, multiparser wouldn't have any chance to read it again.

salemalem commented 3 years ago

I can't handle with pure multiparser either. It says context.request.serverRequest is empty.

I have a form with files and it's posted to


.post("/upload", async (context) => {
    console.log(context);
    console.log(context.request);
    console.log(context.request.serverRequest);
    // const form = await multiParser(context.request.serverRequest);
    // if (form) {
      // console.log(form)
    // }
    context.response.body = context.request.serverRequest;
  });)```

Every console log is empty