Blob.type - Web APIs 编辑
The type
property of a Blob
object returns the MIME type of the file.
Syntax
var mimetype = blob.type
Value
A DOMString
containing the file's MIME type, or an empty string if the type could not be determined.
Example
This example asks the user to select a number of files, then checks each file to make sure it's one of a given set of image file types.
var i, fileInput, files, allowedFileTypes;
// fileInput is a HTMLInputElement: <input type="file" multiple id="myfileinput">
fileInput = document.getElementById("myfileinput");
// files is a FileList object (simliar to NodeList)
files = fileInput.files;
// our application only allows GIF, PNG, and JPEG images
allowedFileTypes = ["image/png", "image/jpeg", "image/gif"];
for (i = 0; i < files.length; i++) {
// Test if file.type is an allowed file type.
if (allowedFileTypes.indexOf(files[i].type) > -1) {
// file type matched is one of allowed file types. Do something here.
}
});
Specifications
Specification | Status | Comment |
---|---|---|
File API The definition of 'Blob.type' in that specification. | Working Draft | Initial definition. |
Browser compatibility
BCD tables only load in the browser
See also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论