mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-13 23:20:05 +00:00
feat(*): recreate package with new name
This commit is contained in:
23
sasjs-tests/src/utils/UploadFile.ts
Normal file
23
sasjs-tests/src/utils/UploadFile.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
export const uploadFile = (file: File, fileName: string, url: string) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const data = new FormData();
|
||||
data.append("file", file);
|
||||
data.append("filename", fileName);
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.withCredentials = true;
|
||||
xhr.addEventListener("readystatechange", function () {
|
||||
if (this.readyState === 4) {
|
||||
let response: any;
|
||||
try {
|
||||
response = JSON.parse(this.responseText);
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
resolve(response);
|
||||
}
|
||||
});
|
||||
xhr.open("POST", url);
|
||||
xhr.setRequestHeader("cache-control", "no-cache");
|
||||
xhr.send(data);
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user