refs #227 Build multiple-form-data in uploadMedia

This commit is contained in:
AkiraFukushima 2020-03-02 22:53:49 +09:00
parent 816b0d42e4
commit 30c85e899d
2 changed files with 6 additions and 11 deletions

View file

@ -1132,20 +1132,15 @@ export default class Mastodon implements MegalodonInterface {
// statuses/media
// ======================================
public async uploadMedia(file: any, description?: string | null, focus?: string | null): Promise<Response<Entity.Attachment>> {
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<MastodonAPI.Entity.Attachment>('/api/v1/media', params).then(res => {
return this.client.post<MastodonAPI.Entity.Attachment>('/api/v1/media', formData).then(res => {
return Object.assign(res, {
data: MastodonAPI.Converter.attachment(res.data)
})

View file

@ -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'. */