Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- submit = () => {
- let object = { ...this.props.values };
- let formData = new FormData();
- for (let property in object) {
- if (object.hasOwnProperty(property)) {
- formData.append(property, object[property]);
- }
- }
- fetch(`${process.env.REACT_APP_SIMCARDS_API}/simcard/neworder/order`, {
- method: "POST",
- mode: "cors",
- headers: {
- Authorization: getBearerAccessToken()
- },
- responseType: "blob",
- body: formData
- })
- .then(response => {
- if (response.ok) {
- return {
- name: response.headers.get("X-File-Name"),
- blob: response.blob()
- };
- } else {
- throw Error(`Request rejected with status ${response.status}`);
- }
- })
- .then(data => {
- return Promise.resolve(data);
- })
- .then(data => {
- return data.blob.then(blob => {
- if (window.navigator && window.navigator.msSaveOrOpenBlob) {
- window.navigator.msSaveOrOpenBlob(blob, data.name);
- } else {
- var url = window.URL.createObjectURL(blob);
- var a = document.createElement("a");
- a.href = url;
- a.download = data.name;
- document.body.appendChild(a);
- a.click();
- a.remove();
- }
- });
- })
- };
Add Comment
Please, Sign In to add comment