Đưa ra một bảng có cột BLOB có tên TOPOGRAPHIC_MAP và cột VARCHAR có tên MAP_NAME, tìm bất kỳ bản đồ nào chứa chuỗi 'Pellow Island' và trả về một chuỗi nhị phân có tên bản đồ được nối ở phía trước bản đồ thực tế.
Một đối tượng Blob đại diện cho một đối tượng giống như tệp của dữ liệu thô, không thay đổi. Các đốm màu đại diện cho dữ liệu không nhất thiết phải ở định dạng gốc JavaScript. (https. // nhà phát triển. mozilla. org/en/docs/Web/API/Blob)
Đôi khi, chúng tôi nhận được Blobs thay vì văn bản thuần túy dưới dạng phản hồi khi nhận tài nguyên từ API. Điều này đặc biệt quan trọng khi phản hồi cho biết đã xảy ra lỗi và mô tả lỗi được lưu trữ trong Blob đó. Do đó, bạn khó có thể đọc được nội dung của Blob
Để đọc nó, bạn cần chuyển đổi nó thành một chuỗi — và một cách dễ dàng để làm điều đó là sử dụng API FileReader
API FileReader có một số phương thức hữu ích như readDataAsUrl(), nhưng hiện tại chúng tôi quan tâm đến phương thức readAsText(). Phương pháp này chấp nhận một Blob và đọc nó dưới dạng văn bản, điều này khá rõ ràng theo tên của nó
Gọi phương thức readAsText sẽ không thực sự trả về văn bản. Thay vào đó, nó kích hoạt một sự kiện có tên là loadend sau khi đọc xong nội dung của đốm màu. Bạn phải xử lý sự kiện này để truy cập nội dung của đốm màu dưới dạng văn bản. Văn bản đó được lưu trữ trong e. srcElement. kết quả, trong đó e là đối tượng sự kiện
Bạn thấy nó có ích chứ? . Cảm ơn nhiều. ^_^
Trong trình duyệt, có các đối tượng cấp cao bổ sung, được mô tả trong API tệp, cụ thể là
// create Blob from a string
let blob = new Blob(["<html>…</html>"], {type: 'text/html'});
// please note: the first argument must be an array [...]
4// create Blob from a string
let blob = new Blob(["<html>…</html>"], {type: 'text/html'});
// please note: the first argument must be an array [...]
4 bao gồm một chuỗi tùy chọn // create Blob from a string
let blob = new Blob(["<html>…</html>"], {type: 'text/html'});
// please note: the first argument must be an array [...]
6 (thường là kiểu MIME), cộng với // create Blob from a string
let blob = new Blob(["<html>…</html>"], {type: 'text/html'});
// please note: the first argument must be an array [...]
7 – một chuỗi các đối tượng // create Blob from a string
let blob = new Blob(["<html>…</html>"], {type: 'text/html'});
// please note: the first argument must be an array [...]
4 khác, chuỗi và // create Blob from a string
let blob = new Blob(["<html>…</html>"], {type: 'text/html'});
// please note: the first argument must be an array [...]
9Cú pháp hàm tạo là
________số 8_______
// create Blob from a string
let blob = new Blob(["<html>…</html>"], {type: 'text/html'});
// please note: the first argument must be an array [...]
7 là một mảng gồm các giá trị // create Blob from a string
let blob = new Blob(["<html>…</html>"], {type: 'text/html'});
// please note: the first argument must be an array [...]
4/// create Blob from a string
let blob = new Blob(["<html>…</html>"], {type: 'text/html'});
// please note: the first argument must be an array [...]
9/// create Blob from a typed array and strings
let hello = new Uint8Array([72, 101, 108, 108, 111]); // "Hello" in binary form
let blob = new Blob([hello, ' ', 'world'], {type: 'text/plain'});
3// create Blob from a typed array and strings
let hello = new Uint8Array([72, 101, 108, 108, 111]); // "Hello" in binary form
let blob = new Blob([hello, ' ', 'world'], {type: 'text/plain'});
4 đối tượng tùy chọn- Loại
// create Blob from a string
let blob = new Blob(["<html>…</html>"], {type: 'text/html'});
// please note: the first argument must be an array [...]
6 – Loại // create Blob from a string
let blob = new Blob(["<html>…</html>"], {type: 'text/html'});
// please note: the first argument must be an array [...]
4, thường là loại MIME, e. g. // create Blob from a typed array and strings
let hello = new Uint8Array([72, 101, 108, 108, 111]); // "Hello" in binary form
let blob = new Blob([hello, ' ', 'world'], {type: 'text/plain'});
7, // create Blob from a typed array and strings
let hello = new Uint8Array([72, 101, 108, 108, 111]); // "Hello" in binary form
let blob = new Blob([hello, ' ', 'world'], {type: 'text/plain'});
8 – có nên chuyển đổi cuối dòng để làm cho ____2_______4 tương ứng với các dòng mới của hệ điều hành hiện tại hay không (blob.slice([byteStart], [byteEnd], [contentType]);
0 hoặc blob.slice([byteStart], [byteEnd], [contentType]);
1). Theo mặc định là blob.slice([byteStart], [byteEnd], [contentType]);
2 (không làm gì), nhưng cũng có thể là blob.slice([byteStart], [byteEnd], [contentType]);
3 (biến đổi)
Ví dụ
// create Blob from a string
let blob = new Blob(["<html>…</html>"], {type: 'text/html'});
// please note: the first argument must be an array [...]
// create Blob from a typed array and strings
let hello = new Uint8Array([72, 101, 108, 108, 111]); // "Hello" in binary form
let blob = new Blob([hello, ' ', 'world'], {type: 'text/plain'});
Chúng tôi có thể trích xuất _______2_______4 lát với
blob.slice([byteStart], [byteEnd], [contentType]);
blob.slice([byteStart], [byteEnd], [contentType]);
5 – byte bắt đầu, theo mặc định là 0blob.slice([byteStart], [byteEnd], [contentType]);
6 – byte cuối cùng (độc quyền, theo mặc định cho đến hết)blob.slice([byteStart], [byteEnd], [contentType]);
7 – // create Blob from a string
let blob = new Blob(["<html>…</html>"], {type: 'text/html'});
// please note: the first argument must be an array [...]
6 của đốm màu mới, theo mặc định giống với nguồn
Các đối số tương tự như
blob.slice([byteStart], [byteEnd], [contentType]);
9, số âm cũng được phép// create Blob from a string
let blob = new Blob(["<html>…</html>"], {type: 'text/html'});
// please note: the first argument must be an array [...]
4 đối tượng là bất biến
Chúng tôi không thể thay đổi dữ liệu trực tiếp trong
// create Blob from a string
let blob = new Blob(["<html>…</html>"], {type: 'text/html'});
// please note: the first argument must be an array [...]
4, nhưng chúng tôi có thể cắt các phần của // create Blob from a string
let blob = new Blob(["<html>…</html>"], {type: 'text/html'});
// please note: the first argument must be an array [...]
4, tạo các đối tượng // create Blob from a string
let blob = new Blob(["<html>…</html>"], {type: 'text/html'});
// please note: the first argument must be an array [...]
4 mới từ chúng, trộn chúng vào một // create Blob from a string
let blob = new Blob(["<html>…</html>"], {type: 'text/html'});
// please note: the first argument must be an array [...]
4 mới, v.v.Hành vi này tương tự như chuỗi JavaScript. chúng ta không thể thay đổi một ký tự trong một chuỗi, nhưng chúng ta có thể tạo một chuỗi mới đã sửa
Có thể dễ dàng sử dụng Blob làm URL cho
<!-- download attribute forces the browser to download instead of navigating -->
<a download="hello.txt" href='#' id="link">Download</a>
<script>
let blob = new Blob(["Hello, world!"], {type: 'text/plain'});
link.href = URL.createObjectURL(blob);
</script>
5, <!-- download attribute forces the browser to download instead of navigating -->
<a download="hello.txt" href='#' id="link">Download</a>
<script>
let blob = new Blob(["Hello, world!"], {type: 'text/plain'});
link.href = URL.createObjectURL(blob);
</script>
6 hoặc các thẻ khác để hiển thị nội dung của nóNhờ có
// create Blob from a string
let blob = new Blob(["<html>…</html>"], {type: 'text/html'});
// please note: the first argument must be an array [...]
6, chúng tôi cũng có thể tải xuống/tải lên các đối tượng // create Blob from a string
let blob = new Blob(["<html>…</html>"], {type: 'text/html'});
// please note: the first argument must be an array [...]
4 và // create Blob from a string
let blob = new Blob(["<html>…</html>"], {type: 'text/html'});
// please note: the first argument must be an array [...]
6 tự nhiên trở thành let link = document.createElement('a');
link.download = 'hello.txt';
let blob = new Blob(['Hello, world!'], {type: 'text/plain'});
link.href = URL.createObjectURL(blob);
link.click();
URL.revokeObjectURL(link.href);
0 trong các yêu cầu mạngHãy bắt đầu với một ví dụ đơn giản. Bằng cách nhấp vào liên kết, bạn tải xuống
// create Blob from a string
let blob = new Blob(["<html>…</html>"], {type: 'text/html'});
// please note: the first argument must be an array [...]
4 được tạo động với nội dung let link = document.createElement('a');
link.download = 'hello.txt';
let blob = new Blob(['Hello, world!'], {type: 'text/plain'});
link.href = URL.createObjectURL(blob);
link.click();
URL.revokeObjectURL(link.href);
2 dưới dạng tệp<!-- download attribute forces the browser to download instead of navigating -->
<a download="hello.txt" href='#' id="link">Download</a>
<script>
let blob = new Blob(["Hello, world!"], {type: 'text/plain'});
link.href = URL.createObjectURL(blob);
</script>
Chúng tôi cũng có thể tạo liên kết động bằng JavaScript và mô phỏng nhấp chuột bằng cách
let link = document.createElement('a');
link.download = 'hello.txt';
let blob = new Blob(['Hello, world!'], {type: 'text/plain'});
link.href = URL.createObjectURL(blob);
link.click();
URL.revokeObjectURL(link.href);
3, sau đó quá trình tải xuống bắt đầu tự độngĐây là mã tương tự khiến người dùng tải xuống
// create Blob from a string
let blob = new Blob(["<html>…</html>"], {type: 'text/html'});
// please note: the first argument must be an array [...]
4 được tạo động, không có bất kỳ HTML nàolet link = document.createElement('a');
link.download = 'hello.txt';
let blob = new Blob(['Hello, world!'], {type: 'text/plain'});
link.href = URL.createObjectURL(blob);
link.click();
URL.revokeObjectURL(link.href);
let link = document.createElement('a');
link.download = 'hello.txt';
let blob = new Blob(['Hello, world!'], {type: 'text/plain'});
link.href = URL.createObjectURL(blob);
link.click();
URL.revokeObjectURL(link.href);
5 lấy một // create Blob from a string
let blob = new Blob(["<html>…</html>"], {type: 'text/html'});
// please note: the first argument must be an array [...]
4 và tạo một URL duy nhất cho nó, ở dạng let link = document.createElement('a');
link.download = 'hello.txt';
let blob = new Blob(['Hello, world!'], {type: 'text/plain'});
link.href = URL.createObjectURL(blob);
link.click();
URL.revokeObjectURL(link.href);
7Đó là giá trị của
let link = document.createElement('a');
link.download = 'hello.txt';
let blob = new Blob(['Hello, world!'], {type: 'text/plain'});
link.href = URL.createObjectURL(blob);
link.click();
URL.revokeObjectURL(link.href);
8 trông như thế nàoblob:https://javascript.info/1e67e00e-860d-40a5-89ae-6ab0cbee6273
Đối với mỗi URL được tạo bởi
let link = document.createElement('a');
link.download = 'hello.txt';
let blob = new Blob(['Hello, world!'], {type: 'text/plain'});
link.href = URL.createObjectURL(blob);
link.click();
URL.revokeObjectURL(link.href);
5, trình duyệt lưu trữ một URL → // create Blob from a string
let blob = new Blob(["<html>…</html>"], {type: 'text/html'});
// please note: the first argument must be an array [...]
4 ánh xạ nội bộ. Vì vậy, các URL như vậy ngắn, nhưng cho phép truy cập vào // create Blob from a string
let blob = new Blob(["<html>…</html>"], {type: 'text/html'});
// please note: the first argument must be an array [...]
4Một URL được tạo (và do đó liên kết với nó) chỉ hợp lệ trong tài liệu hiện tại, khi nó đang mở. Và nó cho phép tham chiếu đến
// create Blob from a string
let blob = new Blob(["<html>…</html>"], {type: 'text/html'});
// please note: the first argument must be an array [...]
4 trong <!-- download attribute forces the browser to download instead of navigating -->
<a download="hello.txt" href='#' id="link">Download</a>
<script>
let blob = new Blob(["Hello, world!"], {type: 'text/plain'});
link.href = URL.createObjectURL(blob);
</script>
6, <!-- download attribute forces the browser to download instead of navigating -->
<a download="hello.txt" href='#' id="link">Download</a>
<script>
let blob = new Blob(["Hello, world!"], {type: 'text/plain'});
link.href = URL.createObjectURL(blob);
</script>
5, về cơ bản là bất kỳ đối tượng nào khác mong đợi một URLCó một tác dụng phụ mặc dù. Mặc dù có một ánh xạ cho một
// create Blob from a string
let blob = new Blob(["<html>…</html>"], {type: 'text/html'});
// please note: the first argument must be an array [...]
4, nhưng bản thân // create Blob from a string
let blob = new Blob(["<html>…</html>"], {type: 'text/html'});
// please note: the first argument must be an array [...]
4 lại nằm trong bộ nhớ. Trình duyệt không thể giải phóng nóÁnh xạ sẽ tự động bị xóa khi tải xuống tài liệu, vì vậy các đối tượng
// create Blob from a string
let blob = new Blob(["<html>…</html>"], {type: 'text/html'});
// please note: the first argument must be an array [...]
4 được giải phóng sau đó. Nhưng nếu một ứng dụng tồn tại lâu dài, thì điều đó sẽ không sớm xảy raVì vậy, nếu chúng tôi tạo một URL, thì
// create Blob from a string
let blob = new Blob(["<html>…</html>"], {type: 'text/html'});
// please note: the first argument must be an array [...]
4 đó sẽ được lưu trong bộ nhớ, ngay cả khi không cần thiết nữablob:https://javascript.info/1e67e00e-860d-40a5-89ae-6ab0cbee6273
9 xóa tham chiếu khỏi ánh xạ bên trong, do đó cho phép xóa // create Blob from a string
let blob = new Blob(["<html>…</html>"], {type: 'text/html'});
// please note: the first argument must be an array [...]
4 (nếu không có tham chiếu nào khác) và giải phóng bộ nhớTrong ví dụ cuối cùng, chúng tôi dự định chỉ sử dụng
// create Blob from a string
let blob = new Blob(["<html>…</html>"], {type: 'text/html'});
// please note: the first argument must be an array [...]
4 một lần để tải xuống ngay lập tức, vì vậy chúng tôi gọi ngay <img src="data:image/png;base64,R0lGODlhDAAMAKIFAF5LAP/zxAAAANyuAP/gaP///wAAAAAAACH5BAEAAAUALAAAAAAMAAwAAAMlWLPcGjDKFYi9lxKBOaGcF35DhWHamZUW0K4mAbiwWtuf0uxFAgA7">
2Trong ví dụ trước với liên kết HTML có thể nhấp, chúng tôi không gọi
<img src="data:image/png;base64,R0lGODlhDAAMAKIFAF5LAP/zxAAAANyuAP/gaP///wAAAAAAACH5BAEAAAUALAAAAAAMAAwAAAMlWLPcGjDKFYi9lxKBOaGcF35DhWHamZUW0K4mAbiwWtuf0uxFAgA7">
2, vì điều đó sẽ làm cho url // create Blob from a string
let blob = new Blob(["<html>…</html>"], {type: 'text/html'});
// please note: the first argument must be an array [...]
4 không hợp lệ. Sau khi thu hồi, do ánh xạ bị xóa nên URL không hoạt động nữaMột giải pháp thay thế cho
let link = document.createElement('a');
link.download = 'hello.txt';
let blob = new Blob(['Hello, world!'], {type: 'text/plain'});
link.href = URL.createObjectURL(blob);
link.click();
URL.revokeObjectURL(link.href);
5 là chuyển đổi // create Blob from a string
let blob = new Blob(["<html>…</html>"], {type: 'text/html'});
// please note: the first argument must be an array [...]
4 thành chuỗi được mã hóa base64Mã hóa đó biểu thị dữ liệu nhị phân dưới dạng một chuỗi ký tự cực kỳ an toàn “có thể đọc được” với mã ASCII từ 0 đến 64. Và điều quan trọng hơn – chúng ta có thể sử dụng mã hóa này trong “data-urls”
Một url dữ liệu có dạng
<img src="data:image/png;base64,R0lGODlhDAAMAKIFAF5LAP/zxAAAANyuAP/gaP///wAAAAAAACH5BAEAAAUALAAAAAAMAAwAAAMlWLPcGjDKFYi9lxKBOaGcF35DhWHamZUW0K4mAbiwWtuf0uxFAgA7">
7. Chúng tôi có thể sử dụng các url như vậy ở mọi nơi, ngang bằng với các url “thông thường”Ví dụ, đây là một mặt cười
<img src="data:image/png;base64,R0lGODlhDAAMAKIFAF5LAP/zxAAAANyuAP/gaP///wAAAAAAACH5BAEAAAUALAAAAAAMAAwAAAMlWLPcGjDKFYi9lxKBOaGcF35DhWHamZUW0K4mAbiwWtuf0uxFAgA7">
Trình duyệt sẽ giải mã chuỗi và hiển thị hình ảnh. 9 tích hợp sẵn. Nó có thể đọc dữ liệu từ Blobs ở nhiều định dạng. Trong chương tiếp theo, chúng tôi sẽ đề cập sâu hơn về nó
Đây là bản demo tải xuống một đốm màu, bây giờ thông qua cơ sở-64
let link = document.createElement('a');
link.download = 'hello.txt';
let blob = new Blob(['Hello, world!'], {type: 'text/plain'});
let reader = new FileReader();
reader.readAsDataURL(blob); // converts the blob to base64 and calls onload
reader.onload = function() {
link.href = reader.result; // data url
link.click();
};
Cả hai cách tạo URL của
// create Blob from a string
let blob = new Blob(["<html>…</html>"], {type: 'text/html'});
// please note: the first argument must be an array [...]
4 đều có thể sử dụng được. Nhưng thường thì let link = document.createElement('a');
link.download = 'hello.txt';
let blob = new Blob(['Hello, world!'], {type: 'text/plain'});
let reader = new FileReader();
reader.readAsDataURL(blob); // converts the blob to base64 and calls onload
reader.onload = function() {
link.href = reader.result; // data url
link.click();
};
1 đơn giản và nhanh hơnURL. tạoObjectURL(blob)
- Chúng ta cần thu hồi chúng nếu quan tâm đến bộ nhớ
- Truy cập trực tiếp vào blob, không “mã hóa/giải mã”
Blob đến url dữ liệu
Chúng tôi có thể tạo
// create Blob from a string
let blob = new Blob(["<html>…</html>"], {type: 'text/html'});
// please note: the first argument must be an array [...]
4 của một hình ảnh, một phần hình ảnh hoặc thậm chí tạo một ảnh chụp màn hình trang. Thật tiện lợi để tải nó lên đâu đóCác thao tác với hình ảnh được thực hiện thông qua phần tử
let link = document.createElement('a');
link.download = 'hello.txt';
let blob = new Blob(['Hello, world!'], {type: 'text/plain'});
let reader = new FileReader();
reader.readAsDataURL(blob); // converts the blob to base64 and calls onload
reader.onload = function() {
link.href = reader.result; // data url
link.click();
};
4- Vẽ một hình ảnh (hoặc một phần của nó) trên canvas bằng canvas. vẽhình ảnh
- Gọi phương thức canvas. toBlob(gọi lại, định dạng, chất lượng) tạo một
// create Blob from a string
let blob = new Blob(["<html>…</html>"], {type: 'text/html'});
// please note: the first argument must be an array [...]
4 và chạy let link = document.createElement('a');
link.download = 'hello.txt';
let blob = new Blob(['Hello, world!'], {type: 'text/plain'});
let reader = new FileReader();
reader.readAsDataURL(blob); // converts the blob to base64 and calls onload
reader.onload = function() {
link.href = reader.result; // data url
link.click();
};
6 cùng với nó khi hoàn tất
Trong ví dụ bên dưới, một hình ảnh chỉ được sao chép, nhưng chúng tôi có thể cắt từ hình ảnh đó hoặc chuyển đổi hình ảnh đó trên canvas trước khi tạo một đốm màu
// take any image
let img = document.querySelector('img');
// make <canvas> of the same size
let canvas = document.createElement('canvas');
canvas.width = img.clientWidth;
canvas.height = img.clientHeight;
let context = canvas.getContext('2d');
// copy image to it (this method allows to cut image)
context.drawImage(img, 0, 0);
// we can context.rotate(), and do many other things on canvas
// toBlob is async operation, callback is called when done
canvas.toBlob(function(blob) {
// blob ready, download it
let link = document.createElement('a');
link.download = 'example.png';
link.href = URL.createObjectURL(blob);
link.click();
// delete the internal blob reference, to let the browser clear memory from it
URL.revokeObjectURL(link.href);
}, 'image/png');
Nếu chúng tôi thích
let link = document.createElement('a');
link.download = 'hello.txt';
let blob = new Blob(['Hello, world!'], {type: 'text/plain'});
let reader = new FileReader();
reader.readAsDataURL(blob); // converts the blob to base64 and calls onload
reader.onload = function() {
link.href = reader.result; // data url
link.click();
};
7 thay vì gọi lại// create Blob from a string
let blob = new Blob(["<html>…</html>"], {type: 'text/html'});
// please note: the first argument must be an array [...]
0Để chụp màn hình một trang, chúng ta có thể sử dụng thư viện như https. //github. com/niklasvh/html2canvas. Những gì nó làm chỉ là đi qua trang và vẽ nó trên
let link = document.createElement('a');
link.download = 'hello.txt';
let blob = new Blob(['Hello, world!'], {type: 'text/plain'});
let reader = new FileReader();
reader.readAsDataURL(blob); // converts the blob to base64 and calls onload
reader.onload = function() {
link.href = reader.result; // data url
link.click();
};
4. Sau đó, chúng ta có thể nhận được một // create Blob from a string
let blob = new Blob(["<html>…</html>"], {type: 'text/html'});
// please note: the first argument must be an array [...]
4 của nó theo cách tương tự như trênHàm tạo
// create Blob from a string
let blob = new Blob(["<html>…</html>"], {type: 'text/html'});
// please note: the first argument must be an array [...]
4 cho phép tạo blob từ hầu hết mọi thứ, kể cả bất kỳ // create Blob from a string
let blob = new Blob(["<html>…</html>"], {type: 'text/html'});
// please note: the first argument must be an array [...]
9 nàoNhưng nếu chúng ta cần thực hiện xử lý cấp thấp, chúng ta có thể lấy
// create Blob from a string
let blob = new Blob(["<html>…</html>"], {type: 'text/html'});
// please note: the first argument must be an array [...]
3 cấp thấp nhất từ // take any image
let img = document.querySelector('img');
// make <canvas> of the same size
let canvas = document.createElement('canvas');
canvas.width = img.clientWidth;
canvas.height = img.clientHeight;
let context = canvas.getContext('2d');
// copy image to it (this method allows to cut image)
context.drawImage(img, 0, 0);
// we can context.rotate(), and do many other things on canvas
// toBlob is async operation, callback is called when done
canvas.toBlob(function(blob) {
// blob ready, download it
let link = document.createElement('a');
link.download = 'example.png';
link.href = URL.createObjectURL(blob);
link.click();
// delete the internal blob reference, to let the browser clear memory from it
URL.revokeObjectURL(link.href);
}, 'image/png');
3// create Blob from a string
let blob = new Blob(["<html>…</html>"], {type: 'text/html'});
// please note: the first argument must be an array [...]
1Khi chúng ta đọc và viết một đốm màu lớn hơn
// take any image
let img = document.querySelector('img');
// make <canvas> of the same size
let canvas = document.createElement('canvas');
canvas.width = img.clientWidth;
canvas.height = img.clientHeight;
let context = canvas.getContext('2d');
// copy image to it (this method allows to cut image)
context.drawImage(img, 0, 0);
// we can context.rotate(), and do many other things on canvas
// toBlob is async operation, callback is called when done
canvas.toBlob(function(blob) {
// blob ready, download it
let link = document.createElement('a');
link.download = 'example.png';
link.href = URL.createObjectURL(blob);
link.click();
// delete the internal blob reference, to let the browser clear memory from it
URL.revokeObjectURL(link.href);
}, 'image/png');
4, việc sử dụng // take any image
let img = document.querySelector('img');
// make <canvas> of the same size
let canvas = document.createElement('canvas');
canvas.width = img.clientWidth;
canvas.height = img.clientHeight;
let context = canvas.getContext('2d');
// copy image to it (this method allows to cut image)
context.drawImage(img, 0, 0);
// we can context.rotate(), and do many other things on canvas
// toBlob is async operation, callback is called when done
canvas.toBlob(function(blob) {
// blob ready, download it
let link = document.createElement('a');
link.download = 'example.png';
link.href = URL.createObjectURL(blob);
link.click();
// delete the internal blob reference, to let the browser clear memory from it
URL.revokeObjectURL(link.href);
}, 'image/png');
5 trở nên tốn nhiều bộ nhớ hơn đối với chúng ta. Tại thời điểm này, chúng ta có thể trực tiếp chuyển đổi blob thành luồngLuồng là một đối tượng đặc biệt cho phép đọc từng phần từ nó (hoặc ghi vào nó). Nó nằm ngoài phạm vi của chúng tôi ở đây, nhưng đây là một ví dụ và bạn có thể đọc thêm tại https. // nhà phát triển. mozilla. org/en-US/docs/Web/API/Streams_API. Luồng thuận tiện cho dữ liệu phù hợp để xử lý từng phần
Phương thức
// take any image
let img = document.querySelector('img');
// make <canvas> of the same size
let canvas = document.createElement('canvas');
canvas.width = img.clientWidth;
canvas.height = img.clientHeight;
let context = canvas.getContext('2d');
// copy image to it (this method allows to cut image)
context.drawImage(img, 0, 0);
// we can context.rotate(), and do many other things on canvas
// toBlob is async operation, callback is called when done
canvas.toBlob(function(blob) {
// blob ready, download it
let link = document.createElement('a');
link.download = 'example.png';
link.href = URL.createObjectURL(blob);
link.click();
// delete the internal blob reference, to let the browser clear memory from it
URL.revokeObjectURL(link.href);
}, 'image/png');
7 của giao diện // create Blob from a string
let blob = new Blob(["<html>…</html>"], {type: 'text/html'});
// please note: the first argument must be an array [...]
4 trả về một // take any image
let img = document.querySelector('img');
// make <canvas> of the same size
let canvas = document.createElement('canvas');
canvas.width = img.clientWidth;
canvas.height = img.clientHeight;
let context = canvas.getContext('2d');
// copy image to it (this method allows to cut image)
context.drawImage(img, 0, 0);
// we can context.rotate(), and do many other things on canvas
// toBlob is async operation, callback is called when done
canvas.toBlob(function(blob) {
// blob ready, download it
let link = document.createElement('a');
link.download = 'example.png';
link.href = URL.createObjectURL(blob);
link.click();
// delete the internal blob reference, to let the browser clear memory from it
URL.revokeObjectURL(link.href);
}, 'image/png');
8 mà khi đọc sẽ trả về dữ liệu chứa trong // create Blob from a string
let blob = new Blob(["<html>…</html>"], {type: 'text/html'});
// please note: the first argument must be an array [...]
4Sau đó, chúng ta có thể đọc từ nó, như thế này
// create Blob from a string
let blob = new Blob(["<html>…</html>"], {type: 'text/html'});
// please note: the first argument must be an array [...]
2Trong khi
// create Blob from a string
let blob = new Blob(["<html>…</html>"], {type: 'text/html'});
// please note: the first argument must be an array [...]
3, // create Blob from a string
let blob = new Blob(["<html>…</html>"], {type: 'text/html'});
// please note: the first argument must be an array [...]
01 và // create Blob from a string
let blob = new Blob(["<html>…</html>"], {type: 'text/html'});
// please note: the first argument must be an array [...]
9 khác là “dữ liệu nhị phân”, a đại diện cho “dữ liệu nhị phân có loại”Điều đó làm cho Blobs thuận tiện cho các thao tác tải lên/tải xuống, vốn rất phổ biến trong trình duyệt
Các phương thức thực hiện yêu cầu web, chẳng hạn như XMLHttpRequest, tìm nạp, v.v., có thể hoạt động với
// create Blob from a string
let blob = new Blob(["<html>…</html>"], {type: 'text/html'});
// please note: the first argument must be an array [...]
4 nguyên bản, cũng như với các loại nhị phân khácChúng ta có thể dễ dàng chuyển đổi giữa
// create Blob from a string
let blob = new Blob(["<html>…</html>"], {type: 'text/html'});
// please note: the first argument must be an array [...]
4 và kiểu dữ liệu nhị phân cấp thấp- Chúng ta có thể tạo một
// create Blob from a string
let blob = new Blob(["<html>…</html>"], {type: 'text/html'});
// please note: the first argument must be an array [...]
4 từ một mảng đã nhập bằng cách sử dụng hàm tạo // create Blob from a string
let blob = new Blob(["<html>…</html>"], {type: 'text/html'});
// please note: the first argument must be an array [...]
06 - Chúng tôi có thể lấy lại
// create Blob from a string
let blob = new Blob(["<html>…</html>"], {type: 'text/html'});
// please note: the first argument must be an array [...]
3 từ Blob bằng cách sử dụng // take any image
let img = document.querySelector('img');
// make <canvas> of the same size
let canvas = document.createElement('canvas');
canvas.width = img.clientWidth;
canvas.height = img.clientHeight;
let context = canvas.getContext('2d');
// copy image to it (this method allows to cut image)
context.drawImage(img, 0, 0);
// we can context.rotate(), and do many other things on canvas
// toBlob is async operation, callback is called when done
canvas.toBlob(function(blob) {
// blob ready, download it
let link = document.createElement('a');
link.download = 'example.png';
link.href = URL.createObjectURL(blob);
link.click();
// delete the internal blob reference, to let the browser clear memory from it
URL.revokeObjectURL(link.href);
}, 'image/png');
3, sau đó tạo chế độ xem trên đó để xử lý nhị phân cấp thấp
Luồng chuyển đổi rất hữu ích khi chúng tôi cần xử lý đốm màu lớn. Bạn có thể dễ dàng tạo một
// take any image
let img = document.querySelector('img');
// make <canvas> of the same size
let canvas = document.createElement('canvas');
canvas.width = img.clientWidth;
canvas.height = img.clientHeight;
let context = canvas.getContext('2d');
// copy image to it (this method allows to cut image)
context.drawImage(img, 0, 0);
// we can context.rotate(), and do many other things on canvas
// toBlob is async operation, callback is called when done
canvas.toBlob(function(blob) {
// blob ready, download it
let link = document.createElement('a');
link.download = 'example.png';
link.href = URL.createObjectURL(blob);
link.click();
// delete the internal blob reference, to let the browser clear memory from it
URL.revokeObjectURL(link.href);
}, 'image/png');
8 từ một đốm màu. Phương thức // take any image
let img = document.querySelector('img');
// make <canvas> of the same size
let canvas = document.createElement('canvas');
canvas.width = img.clientWidth;
canvas.height = img.clientHeight;
let context = canvas.getContext('2d');
// copy image to it (this method allows to cut image)
context.drawImage(img, 0, 0);
// we can context.rotate(), and do many other things on canvas
// toBlob is async operation, callback is called when done
canvas.toBlob(function(blob) {
// blob ready, download it
let link = document.createElement('a');
link.download = 'example.png';
link.href = URL.createObjectURL(blob);
link.click();
// delete the internal blob reference, to let the browser clear memory from it
URL.revokeObjectURL(link.href);
}, 'image/png');
7 của giao diện // create Blob from a string
let blob = new Blob(["<html>…</html>"], {type: 'text/html'});
// please note: the first argument must be an array [...]
4 trả về một // take any image
let img = document.querySelector('img');
// make <canvas> of the same size
let canvas = document.createElement('canvas');
canvas.width = img.clientWidth;
canvas.height = img.clientHeight;
let context = canvas.getContext('2d');
// copy image to it (this method allows to cut image)
context.drawImage(img, 0, 0);
// we can context.rotate(), and do many other things on canvas
// toBlob is async operation, callback is called when done
canvas.toBlob(function(blob) {
// blob ready, download it
let link = document.createElement('a');
link.download = 'example.png';
link.href = URL.createObjectURL(blob);
link.click();
// delete the internal blob reference, to let the browser clear memory from it
URL.revokeObjectURL(link.href);
}, 'image/png');
8 mà khi đọc sẽ trả về dữ liệu chứa trong đốm màu
Chúng tôi có thể lưu trữ chuỗi trong BLOB không?
BLOB là một chuỗi byte hoặc ký tự không được giải thích, được lưu trữ dưới dạng một giá trị trong một cột. Các ví dụ phổ biến của BLOB là các tệp hình ảnh hoặc âm thanh. Mặc dù BLOB thường lớn, nhưng bạn có thể lưu trữ chúng ở bất kỳ kiểu dữ liệu chuỗi ký tự hoặc chuỗi nhị phân nào chẳng hạn như CHAR, VARCHAR, NCHAR, BINARY, VARBINARY và .
BLOB có phải là văn bản không?
BLOB là viết tắt của Đối tượng lớn nhị phân và như tên gọi của nó, nó có thể được sử dụng để lưu trữ dữ liệu nhị phân trong khi TEXT được sử dụng để lưu trữ số lượng lớn chuỗi. BLOB can be used to store binary data that means we can store pictures, videos, sounds and programs also.
Kiểu dữ liệu blob là gì?
BLOB là một đối tượng lớn nhị phân có thể chứa một lượng dữ liệu thay đổi . Bốn loại BLOB là TINYBLOB , BLOB , MEDIUMBLOB và LONGBLOB. Chúng chỉ khác nhau về độ dài tối đa của các giá trị mà chúng có thể giữ. Bốn loại TEXT là TINYTEXT , TEXT , MEDIUMTEXT và LONGTEXT.
Làm cách nào để chuyển đổi BLOB thành chuỗi trong Java?
Blob blob = rs. getBlob(cloumnName[i]); . getBytes(1, (int) blob. chiều dài());