Giter Club home page Giter Club logo

multiparser's People

Contributors

gjuoun avatar gungunfebrianza avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

multiparser's Issues

Opine support

Does this module work with opine. If so how would one implement it to handle file uploading.

Can't have multiparser with upload

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 ...

if send request many times, only half can request success

async function parseFormData(contentType: string, request: ServerRequest) {
  const boundaryReg = /boundary=(.+)/i;
  const match = contentType.match(boundaryReg);
  const boundary = match?.[1];
  const res: {[key: string]: string | FormFile} = {};
  if(boundary){
    // const mr = new MultipartReader(request.r, boundary);
    // const form = await mr.readForm(2 * 1024 * 1024);
    const form: any = await multiParser(request);
    if(form){
      for(const [key, value] of form.entries()){
        const newValue: any = value || {};
        const val = <FormFile>value;
        if(val.content){
          const decoder = new TextDecoder();
          newValue.value = decoder.decode(val.content);
        }
        res[key] = <string | FormFile>newValue;
      }
    }
  }
  return res;
}

    const originRequest = ctx.request.serverRequest;
    const contentType = ctx.request.headers.get('content-type') || 'text';
    // set params data
    ctx.query = parseQuery(ctx.request.url.search.slice(1));
    // init request body
    const body = {type: '', value: {}};
    if(ctx.request.hasBody){
      // field to save body
      let _body: any;
      // field to save type
      let type: string;
      const contentTypeFilter = getContentType(contentType);
      // deal with form-data first
      if(contentTypeFilter.isFormData){
        _body = await parseFormData(contentType, originRequest);
        type = 'formData';
      }
   }

This is the result and some information
image
image
I think this question casued by

 const form = await multiParser(request);

If I delete it, it worked

how to use with oak?

import { multiParser } from 'https://deno.land/x/multiparser/mod.ts'
import Subscriptions from '../models/subscriptions.ts';

class Controller {
  async post(context: any) {
    const body = await multiParser(context.request.serverRequest);
    // const existing = await Subscriptions.where('email', body.email).get()
    const existing = [];

    console.log(body);

    if (existing.length) {
      return (context.response.body = "Email already exists");
    }

    const subscription = {};
    // const subscription = await Subscriptions.create({
    //   id: crypto.randomUUID(),
    //   email: body.email,
    // });

    context.response.body = subscription;
  }
}

export default new Controller();

I get error:
[uncaught oak error]: TypeError - Cannot read property 'headers' of undefined

Outdated hardcoded std lib dep

Trying to use this but I get the following error:

error: TS2345 [ERROR]: Argument of type 'import("https://deno.land/[email protected]/http/server").ServerRequest' is not assignable to parameter of type 'import("https://deno.land/[email protected]/http/server").ServerRequest'.
  Types of property 'r' are incompatible.
    Type 'import("https://deno.land/[email protected]/io/bufio").BufReader' is not assignable to type 'import("https://deno.land/[email protected]/io/bufio").BufReader'.
      Types have separate declarations of a private property 'buf'.
	const form = await multiParserV2(req, {})

It seems the lib hard-codes the std lib in mod.ts, and it has not been updated since 0.61. Current version appears to be 0.74.

multiparser on Deno 1.2

Hello. I've updated to Deno 1.2 but it gives the following errors.

`error: TS2345 [ERROR]: Argument of type 'string | URL' is not assignable to parameter of type 'string'.
Type 'URL' is not assignable to type 'string'.
return new URL(url).pathname
~~~
at https://deno.land/[email protected]/path/win32.ts:917:18

TS2345 [ERROR]: Argument of type 'string | URL' is not assignable to parameter of type 'string'.
Type 'URL' is not assignable to type 'string'.
return new URL(url).pathname;
~~~
at https://deno.land/[email protected]/path/posix.ts:438:18

Found 2 errors.`

Can you please help me on this. This way I can keep using your code.

Thanks!

Where is the filepath ?

I recently switched from nodejs to deno and came to use this library for form parsing as alternative to formiddable. It seems that there is no filepath property for a file if sent from a form. Why is that ? Formiddable seems to have it and this is now not allowing me to read file and send as buffer. i have tried working with Uint8array but sending it as base64 has some complications that dont get resolved.

multiParser has no response

I use this parser. But it has no response.
I used postman to send multipart/form-data request, but it was sending forever and never stop.
I think it had no condition to stop read? or other reason?
image
The output terminal had no error message. If I cancel the request, It showed error.
image
I think thats the same question here denoland/deno#5830

deno-demo2.zip

Hardcoded stdlib dep causes problem

Oak uses std 0.95.0, which means multiparser can't be used since it relies on 0.89. It just doesn't work.

This prevents us from making a necessary Deno upgrade

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.