mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 07:25:44 +01:00
Add upload api for files
This commit is contained in:
@@ -54,17 +54,15 @@ class ApiClient {
|
|||||||
return this.httpRequestWithJSONBody("POST", url, contentType, payload);
|
return this.httpRequestWithJSONBody("POST", url, contentType, payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
postBinary(contentType: string, url: string, files: File[]) {
|
postBinary(url: string, fileAppender: FormData => void) {
|
||||||
let formData = new FormData();
|
let formData = new FormData();
|
||||||
for (let i = 0; i < files.length; i++) {
|
fileAppender(formData);
|
||||||
formData.append("file" + i, files[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
let options: RequestOptions = {
|
let options: RequestOptions = {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: formData
|
body: formData
|
||||||
};
|
};
|
||||||
return this.httpRequestWithBinaryBody(options, contentType, url);
|
return this.httpRequestWithBinaryBody(options, url);
|
||||||
}
|
}
|
||||||
|
|
||||||
put(url: string, payload: any, contentType: string = "application/json") {
|
put(url: string, payload: any, contentType: string = "application/json") {
|
||||||
@@ -97,13 +95,15 @@ class ApiClient {
|
|||||||
method: method,
|
method: method,
|
||||||
body: JSON.stringify(payload)
|
body: JSON.stringify(payload)
|
||||||
};
|
};
|
||||||
return this.httpRequestWithBinaryBody(options, contentType, url);
|
return this.httpRequestWithBinaryBody(options, url, contentType);
|
||||||
}
|
}
|
||||||
|
|
||||||
httpRequestWithBinaryBody(options: RequestOptions, contentType: string, url: string) {
|
httpRequestWithBinaryBody(options: RequestOptions, url: string, contentType?: string) {
|
||||||
options = Object.assign(options, fetchOptions);
|
options = Object.assign(options, fetchOptions);
|
||||||
|
if (contentType) {
|
||||||
// $FlowFixMe
|
// $FlowFixMe
|
||||||
options.headers["Content-Type"] = contentType;
|
options.headers["Content-Type"] = contentType;
|
||||||
|
}
|
||||||
|
|
||||||
return fetch(createUrl(url), options).then(handleFailure);
|
return fetch(createUrl(url), options).then(handleFailure);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user