Skip to content

Commit 1c2b015

Browse files
authored
Merge pull request #43 from povio/feat/file-upload-method
fix the formdata on fileupload
2 parents 7582122 + 73e7215 commit 1c2b015

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@povio/openapi-codegen-cli",
3-
"version": "1.2.8",
3+
"version": "1.2.9",
44
"main": "./dist/index.js",
55
"bin": {
66
"openapi-codegen": "./dist/sh.js"

src/generators/templates/partials/query-use-mutation.hbs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ export const {{queryName endpoint mutation=true}} = (options?: AppMutationOption
1414

1515
if (file && uploadInstructions.url) {
1616
const method = (data?.method?.toLowerCase() ?? "put") as 'put' | 'post';
17+
let dataToSend: File | FormData = file;
18+
if (method === "post") {
19+
dataToSend = new FormData();
20+
dataToSend.append('file', file);
21+
if (uploadInstructions.fields) {
22+
for (const [key, value] of uploadInstructions.fields) {
23+
dataToSend.append(key, value);
24+
}
25+
}
26+
}
1727
await axios[method](uploadInstructions.url, file, {
1828
headers: {
1929
"Content-Type": file.type,

0 commit comments

Comments
 (0)