// the list of the accepted types since we need it always it's better to
// make it global instead of local to the onchange litener,and even you can
// add other types dynamically as well;
const acceptedTypes = ["text/csv","text/x-csv","application/x-csv","application/csv","text/x-comma-separated-values","text/comma-separated-values","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","application/vnd.ms-excel"];
document.querySelector("[type='file']").onchange = function() {
if(!acceptedTypes.includes(this.files[0].type)) {
console.log("This file is not allowed for upload");
// if the file is not allowed then clear the value of the upload element
this.value = "";
}
};
如果仅在用户拖放文件时希望这种行为,则可以像这样自定义
const acceptedTypes = ["text/csv","application/vnd.ms-excel"];
// global variable to hold if the user has dragged the file or not
let isDragged = false;
// the `ondragover` gets triggered before the `onchange` event so it works as expected
document.querySelector("[type='file']").ondragover = function() {
isDragged = true;
};
document.querySelector("[type='file']").onchange = function() {
// if there was no drag then do nothing
if(!isDragged) return;
if(!acceptedTypes.includes(this.files[0].type)) {
console.log("This file is not allowed for upload");
// if the file is not allowed then clear the value of the upload element
this.value = "";
}
isDragged = false;
};
,
您只需要添加一个事件监听器和函数来接受或拒绝该文件:
fileInput.addEventListener("change",func);
var func = function() {
if(fileInput.files[0].type == /*insert your file types here*/) {
//accept file and do stuff with it
} else {
//reject and tell user that is was rejected and why
}
}
当您执行交易时,效果将与单独发布资源相同。在 POST 中,服务器 确定资源 ID。在常规 POST 中,id 只是被忽略或引发错误。在事务中,id 用于管理跨事务的引用解析,但服务器仍然选择持久资源的 id(并相应地更新所有引用)。如果要控制事务中的资源 ID 值,请使用 PUT 而不是 POST。 (请注意,并非所有服务器都允许“更新插入” - 即在特定资源位置执行创建的 PUT。)有关详细信息,请参阅 http://hl7.org/fhir/http.html#upsert。