Skip to content

Commit e66387a

Browse files
committed
feat: update example html
1 parent e7821e7 commit e66387a

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

example/basic.html

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,22 +85,25 @@
8585
const downloadLink = URL.createObjectURL(output)
8686
logDom.innerHTML += '&nbsp;<a href="' + downloadLink + '" download="' + file.name + '">download compressed image</a>'
8787
document.getElementById('preview-after-compress').src = downloadLink
88+
return uploadToServer(output)
8889
})
8990

90-
// await uploadToServer(output)
9191

9292
function onProgress (p) {
9393
progressDom.innerHTML = '(' + p + '%' + ')'
9494
}
9595
}
9696

9797
function uploadToServer (file) {
98-
var formData = new FormData()
99-
formData.append('image', file)
100-
return fetch('http://localhost/image-upload-api', {
98+
const formData = new FormData()
99+
formData.append('image', file, file.name)
100+
const url = 'http://localhost:3000/image-upload-api'
101+
console.log('calling api', url, 'with data', Array.from(formData.entries())[0])
102+
return fetch(url, {
101103
method: 'POST',
102104
body: formData
103-
})
105+
}).then(res => res.json())
106+
.then(body => console.log('got server response', body))
104107
}
105108
</script>
106109
</body>

example/development.html

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,30 +79,32 @@
7979
useWebWorker: useWebWorker,
8080
onProgress: onProgress
8181
}
82-
imageCompression(file, options).then(function (output) {
83-
logDom.innerHTML += ', output size:' + (output.size / 1024 / 1024).toFixed(2) + 'mb'
84-
console.log('output', output)
85-
const downloadLink = URL.createObjectURL(output)
86-
logDom.innerHTML += '&nbsp;<a href="' + downloadLink + '" download="' + file.name + '">download compressed image</a>'
87-
document.getElementById('preview-after-compress').src = downloadLink
88-
// uploadToServer(output)
89-
})
90-
91-
92-
82+
imageCompression(file, options)
83+
.then(function (output) {
84+
logDom.innerHTML += ', output size:' + (output.size / 1024 / 1024).toFixed(2) + 'mb'
85+
console.log('output', output)
86+
const downloadLink = URL.createObjectURL(output)
87+
logDom.innerHTML += '&nbsp;<a href="' + downloadLink + '" download="' + file.name + '">download compressed image</a>'
88+
document.getElementById('preview-after-compress').src = downloadLink
89+
return uploadToServer(output)
90+
})
91+
9392
function onProgress (p) {
9493
console.log('onProgress', p)
9594
progressDom.innerHTML = '(' + p + '%' + ')'
9695
}
9796
}
9897

9998
function uploadToServer (file) {
100-
var formData = new FormData()
99+
const formData = new FormData()
101100
formData.append('image', file, file.name)
102-
return fetch('http://localhost/image-upload-api', {
101+
const url = 'http://localhost:3000/image-upload-api'
102+
console.log('calling api', url, 'with data', Array.from(formData.entries())[0])
103+
return fetch(url, {
103104
method: 'POST',
104105
body: formData
105-
})
106+
}).then(res => res.json())
107+
.then(body => console.log('got server response', body))
106108
}
107109
</script>
108110
</body>

0 commit comments

Comments
 (0)