GithubHelp home page GithubHelp logo

multiparser on Deno 1.2 about multiparser HOT 6 CLOSED

osorito avatar osorito commented on July 28, 2024
multiparser on Deno 1.2

from multiparser.

Comments (6)

gungunfebrianza avatar gungunfebrianza commented on July 28, 2024

this is the problem described in #4 .

from multiparser.

gjuoun avatar gjuoun commented on July 28, 2024

v2.0.1 is out. Please check it out.

https://github.com/deligenius/multiparser/releases/tag/v2.0.1

from multiparser.

osorito avatar osorito commented on July 28, 2024

Tried a simple example.

export const createPost2 = async (ctx: any) => {
try{
const form = await multiParserV2(ctx.request.serverRequest);
//console.log(JSON.stringify(form,null,2));
console.log(title ${form?.fields.title});
console.log(content ${form?.fields.content});
console.log(creator ${form?.fields.creator});
console.log(imageUrl ${form?.files.imageUrl.filename});
ctx.response.status = 201;
ctx.response.body = { message: 'Post created succesfully', post: {}, creator: {_id: '233', name: ''},imageUrl:form?.files.imageUrl };
}catch(err){
console.log(err);
}
};

But gave this output.

If I comment this line
console.log(imageUrl ${form?.files.imageUrl.filename});

it works. But if i enable it , it gives this error.

error: TS2339 [ERROR]: Property 'filename' does not exist on type 'FormFile | FormFile[]'.
Property 'filename' does not exist on type 'FormFile[]'.
console.log(imageUrl ${form?.files.imageUrl.filename});

I know the filename exists, because i can see it on the return from the api.

Screen Shot 2020-07-23 at 11 32 30 AM

from multiparser.

gjuoun avatar gjuoun commented on July 28, 2024

A field may contain many files, before use that, you need to cast type

(<FormFileV2>form?.files).imageUrl

from multiparser.

osorito avatar osorito commented on July 28, 2024

It works!

Here is the working example

export const createPost2 = async (ctx: any) => {
try{
const form: FormV2 = await multiParserV2(ctx.request.serverRequest) as FormV2 ;
//console.log(JSON.stringify(form,null,2));
console.log(title ${form?.fields.title});
console.log(content ${form?.fields.content});
console.log(creator ${form?.fields.creator});
console.log(imageUrl ${(<FormFileV2>form?.files.imageUrl).filename});
await Deno.writeFile(./images/test.png, (form?.files.imageUrl).content);
ctx.response.status = 201;
ctx.response.body = { message: 'Post created succesfully', post: {}, creator: {_id: '233', name: ''},imageUrl:form?.files.imageUrl };
}catch(err){
console.log(err);
}
};

from multiparser.

gjuoun avatar gjuoun commented on July 28, 2024

I'm glad it works for you

from multiparser.

Related Issues (12)

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.