Comments (6)
this is the problem described in #4 .
from multiparser.
v2.0.1 is out. Please check it out.
https://github.com/deligenius/multiparser/releases/tag/v2.0.1
from multiparser.
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.
from multiparser.
A field may contain many files, before use that, you need to cast type
(<FormFileV2>form?.files).imageUrl
from multiparser.
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.
I'm glad it works for you
from multiparser.
Related Issues (12)
- multiParser has no response HOT 3
- if send request many times, only half can request success HOT 8
- Can't have multiparser with upload HOT 2
- [email protected] is obselete HOT 2
- Apply options for multiparser V2 HOT 1
- Outdated hardcoded std lib dep HOT 2
- Hardcoded stdlib dep causes problem HOT 2
- how to use with oak? HOT 2
- Opine support HOT 1
- Where is the filepath ? HOT 1
- Import 'https://deno.land/x/[email protected]' failed, not found.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from multiparser.