Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public sendFile(file: File, visibility: 'public' | 'private' = 'private'): Promise<SocrateFile> {
- const formData = new FormData();
- const xhr = new XMLHttpRequest();
- const url = `${environment.API_URL}files?visibility=${visibility}`;
- formData.append('file', file, file.name);
- return this.auth.getJWT().then(jwt => {
- xhr.open('POST', url, true);
- xhr.setRequestHeader('Authorization', jwt);
- return new Promise<SocrateFile>((res, rej) => {
- xhr.onload = () => {
- const response = JSON.parse(xhr.response);
- if (!response.id) {
- console.error(response);
- rej();
- } else {
- res(response);
- }
- };
- xhr.send(formData); // multipart/form-data
- });
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement