diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index df7b4190be..c9fcc4f6e4 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -6,8 +6,8 @@ const PUBLIC_AND_EXTERNAL_TIMELINE_URL = '/api/statuses/public_and_external_time const FAVORITE_URL = '/api/favorites/create' const UNFAVORITE_URL = '/api/favorites/destroy' const STATUS_UPDATE_URL = '/api/statuses/update.json' +const MEDIA_UPLOAD_URL = '/api/statusnet/media/upload' // const CONVERSATION_URL = '/api/statusnet/conversation/'; -// const MEDIA_UPLOAD_URL = '/api/statusnet/media/upload'; // const FORM_CONTENT_TYPE = {'Content-Type': 'application/x-www-form-urlencoded'}; @@ -75,12 +75,23 @@ const postStatus = ({credentials, status, mediaIds, inReplyToStatusId}) => { }) } +const uploadMedia = ({formData, credentials}) => { + return fetch(MEDIA_UPLOAD_URL, { + body: formData, + method: 'POST', + headers: authHeaders(credentials) + }) + .then((response) => response.text()) + .then((text) => (new DOMParser()).parseFromString(text, 'application/xml')) +} + const apiService = { verifyCredentials, fetchTimeline, favorite, unfavorite, - postStatus + postStatus, + uploadMedia } export default apiService