Closed osorito closed 4 years ago
this is the problem described in #4 .
v2.0.1 is out. Please check it out.
https://github.com/deligenius/multiparser/releases/tag/v2.0.1
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.
A field may contain many files, before use that, you need to cast type
(<FormFileV2>form?.files).imageUrl
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
, (
I'm glad it works for you
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
Found 2 errors.`
Can you please help me on this. This way I can keep using your code.
Thanks!