有人可以帮我把这些功能之间的点联系起来吗?我可以上传,但是如何获取我刚刚上传的文件的 ID 以更新主机文档库中文件上的元数据列?
非常感谢!
function uploadDocument(buffer, fileName) {
var url = String.format("{0}/_api/Web/Lists/getByTitle('Project Documents')/RootFolder/Files/Add(url='{1}', overwrite=true)",
_spPageContextInfo.webAbsoluteUrl, fileName);
var call = jQuery.ajax({
url: url,
type: "POST",
data: buffer,
processData: false,
headers: {
Accept: "application/json;odata=verbose",
"X-RequestDigest": jQuery("#__REQUESTDIGEST").val(),
"Content-Length": buffer.byteLength
}
});
return call;
}
function getItem(file) {
var call = jQuery.ajax({
url: file.ListItemAllFields.__deferred.uri,
type: "GET",
dataType: "json",
headers: {
Accept: "application/json;odata=verbose"
}
});
return call;
}
function updateItemFields(item) {
var now = new Date();
var call = jQuery.ajax({
url: _spPageContextInfo.webAbsoluteUrl +
"/_api/Web/Lists/getByTitle('Project Documents')/Items(" +
item.Id + ")",
type: "POST",
data: JSON.stringify({
"__metadata": { type: "SP.Data.Project_x0020_DocumentsItem" },
CoordinatorId: _spPageContextInfo.userId,
Year: now.getFullYear()
}),
headers: {
Accept: "application/json;odata=verbose",
"Content-Type": "application/json;odata=verbose",
"X-RequestDigest": jQuery("#__REQUESTDIGEST").val(),
"IF-MATCH": item.__metadata.etag,
"X-Http-Method": "MERGE"
}
});
return call;
}