added upload functionality (#758)

Co-authored-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de>
Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de>
Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
Philip Molares 2020-12-16 23:07:09 +01:00 committed by GitHub
parent 8ce344512c
commit 0c0841639a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 401 additions and 73 deletions

View file

@ -18,3 +18,21 @@ export const getProxiedUrl = async (imageUrl: string): Promise<ImageProxyRespons
expectResponseCode(response)
return await response.json() as Promise<ImageProxyResponse>
}
export interface UploadedMedia {
link: string
}
export const uploadFile = async (noteId: string, contentType: string, media: Blob): Promise<UploadedMedia> => {
const response = await fetch(getApiUrl() + '/media/upload', {
...defaultFetchConfig,
headers: {
'Content-Type': contentType,
'HedgeDoc-Note': noteId
},
method: 'POST',
body: media
})
expectResponseCode(response, 201)
return await response.json() as Promise<UploadedMedia>
}