refs #227 Build multiple-form-data in uploadMedia
This commit is contained in:
parent
816b0d42e4
commit
30c85e899d
|
@ -1132,20 +1132,15 @@ export default class Mastodon implements MegalodonInterface {
|
||||||
// statuses/media
|
// statuses/media
|
||||||
// ======================================
|
// ======================================
|
||||||
public async uploadMedia(file: any, description?: string | null, focus?: string | null): Promise<Response<Entity.Attachment>> {
|
public async uploadMedia(file: any, description?: string | null, focus?: string | null): Promise<Response<Entity.Attachment>> {
|
||||||
let params = {
|
const formData = new FormData()
|
||||||
file: file
|
formData.append('file', file)
|
||||||
}
|
|
||||||
if (description) {
|
if (description) {
|
||||||
params = Object.assign(params, {
|
formData.append('description', description)
|
||||||
description: description
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
if (focus) {
|
if (focus) {
|
||||||
params = Object.assign(params, {
|
formData.append('focus', focus)
|
||||||
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, {
|
return Object.assign(res, {
|
||||||
data: MastodonAPI.Converter.attachment(res.data)
|
data: MastodonAPI.Converter.attachment(res.data)
|
||||||
})
|
})
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
/* Basic Options */
|
/* Basic Options */
|
||||||
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
|
"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'. */
|
"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. */
|
// "allowJs": true, /* Allow javascript files to be compiled. */
|
||||||
// "checkJs": true, /* Report errors in .js files. */
|
// "checkJs": true, /* Report errors in .js files. */
|
||||||
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
|
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
|
||||||
|
|
Loading…
Reference in a new issue