-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.html
92 lines (76 loc) · 2.94 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
</head>
<body>
<div class="container mt-4">
<div class="row mt-4">
<div class="col-md-12 card mt-4">
<form>
<div class="form-group">
<label for="fileInput">Select a File: </label>
<input id="fileInput" class="form-control"
type="file">
</div>
<input class="btn btn-primary m-1"
type="button" onclick="submitHandler()"
value="Upload">
</form>
<button class="btn btn-warning"
onclick="downloadFile()">
Download
</button>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.12.9/dist/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<script>
let imageURL;
function submitHandler(){
console.log("click");
const fileInput = document.getElementById('fileInput');
console.log(fileInput.files);
const image = fileInput.files[0];
// Multipart file
const formData = new FormData();
formData.append('image_file', image);
formData.append('size', 'auto');
const apiKey = 'PASTE_YOUR_API_KEY';
fetch('https://api.remove.bg/v1.0/removebg',{
method:'POST',
headers: {
'X-Api-Key': apiKey
},
body: formData
})
.then(function(reponse){
return reponse.blob()
})
.then(function(blob){
console.log(blob);
const url = URL.createObjectURL(blob);
imageURL = url;
const img = document.createElement('img');
img.src = url;
document.body.appendChild(img);
})
.catch();
}
function downloadFile(){
var anchorElement = document.createElement('a'); //<a></a>
anchorElement.href = imageURL;
anchorElement.download = 'naciasv.png';
document.body.appendChild(anchorElement);
anchorElement.click();
document.body.removeChild(anchorElement);
}
</script>
</body>
</html>