From 30c85e899d5bf84647d20eb57be6cca70ca052e9 Mon Sep 17 00:00:00 2001
From: AkiraFukushima
Date: Mon, 2 Mar 2020 22:53:49 +0900
Subject: [PATCH] refs #227 Build multiple-form-data in uploadMedia
---
src/mastodon.ts | 15 +++++----------
tsconfig.json | 2 +-
2 files changed, 6 insertions(+), 11 deletions(-)
diff --git a/src/mastodon.ts b/src/mastodon.ts
index 3131567..392db8e 100644
--- a/src/mastodon.ts
+++ b/src/mastodon.ts
@@ -1132,20 +1132,15 @@ export default class Mastodon implements MegalodonInterface {
// statuses/media
// ======================================
public async uploadMedia(file: any, description?: string | null, focus?: string | null): Promise> {
- let params = {
- file: file
- }
+ const formData = new FormData()
+ formData.append('file', file)
if (description) {
- params = Object.assign(params, {
- description: description
- })
+ formData.append('description', description)
}
if (focus) {
- params = Object.assign(params, {
- focus: focus
- })
+ formData.append('focus', focus)
}
- return this.client.post('/api/v1/media', params).then(res => {
+ return this.client.post('/api/v1/media', formData).then(res => {
return Object.assign(res, {
data: MastodonAPI.Converter.attachment(res.data)
})
diff --git a/tsconfig.json b/tsconfig.json
index 6b7a42b..7f69432 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -3,7 +3,7 @@
/* Basic Options */
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
- "lib": ["es6"], /* Specify library files to be included in the compilation. */
+ "lib": ["es6", "dom"], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */