-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
34 lines (31 loc) · 1.2 KB
/
Copy pathscript.js
File metadata and controls
34 lines (31 loc) · 1.2 KB
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
document.addEventListener('paste', function(event) {
var items = (event.clipboardData || event.originalEvent.clipboardData).items;
for (var index in items) {
var item = items[index];
if (item.kind === 'file') {
var blob = item.getAsFile();
var reader = new FileReader();
reader.onload = function(event) {
var img = document.createElement('img');
img.src = event.target.result;
document.querySelector('.html-content').appendChild(img);
// 여기에서 서버로 이미지 업로드 로직을 추가할 수 있습니다.
uploadImageToServer(event.target.result);
};
reader.readAsDataURL(blob);
}
}
});
function uploadImageToServer(imageData) {
// 이미지 데이터를 서버로 전송하는 AJAX 요청
fetch('/upload', {
method: 'POST',
body: JSON.stringify({image: imageData}),
headers: {
'Content-Type': 'application/json'
}
})
.then(response => response.json())
.then(data => console.log('업로드 성공:', data))
.catch(error => console.error('업로드 실패:', error));
}