Reputation: 229
I'm running a small code to upload file in a SharePoint 2016 document library and to change a metadata.
Sometimes (but really often) my code returns error "Error making HttpClient request in queryable [404] Not Found" with the message "Item does not exist. It may have been deleted by another user."
This is my code:
pnp.sp.web.getFolderByServerRelativeUrl("/sites/mysite/ConfigDL").files.add(fileOgg.name, fileOgg, true).then(function (data) {
var RelativeUrls="/sites/mysite/ConfigDL/"+fileOgg.name;
//Retrive Document which is uploaded. Start
pnp.sp.web.getFolderByServerRelativeUrl(RelativeUrls).getItem().then(item => {
//update start Below Call to Doc List will update the Row baseed on Item.ID
pnp.sp.web.lists.getByTitle("ConfigDL").items.getById(item.ID).update({
Number: ""+number+""
}).then(r => {
alert(file.name + " upload successfully!");
});//update end
}); //Retrive Doc Info End
}); //Upload Document End
I can't get why this error happens randomly and what's wrong with my code. Any suggestion?
Upvotes: 1
Views: 714
Reputation: 5493
Sample test code in my SharePoint online, it should be same as SharePoint 2016.
<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pnp-pnpjs/1.3.4/pnpjs.es5.umd.bundle.min.js"></script>
<script type="text/javascript">
function UpLoadFile() {
var input = document.getElementById("thefileinput");
var fileOgg = input.files[0];
pnp.sp.web.getFolderByServerRelativeUrl("/sites/lee/MyDoc3").files.add(fileOgg.name, fileOgg, true).then(function (data) {
var RelativeUrls = "/sites/lee/MyDoc3/" + fileOgg.name;
//Retrive Document which is uploaded. Start
pnp.sp.web.getFolderByServerRelativeUrl(RelativeUrls).getItem().then(item => {
//update start Below Call to Doc List will update the Row baseed on Item.ID
pnp.sp.web.lists.getByTitle("MyDoc3").items.getById(item.ID).update({
Test: "testvalue"
}).then(r => {
alert(fileOgg.name + " upload successfully!");
});//update end
}); //Retrive Doc Info End
}); //Upload Document End
//pnp.sp.web.getFolderByServerRelativeUrl("/sites/lee/Shared Documents/asd").getItem().then(item => {
// console.log(item);
//});
}
</script>
<input id="thefileinput" type="file" />
<br />
<input id="Button1" onclick="UpLoadFile()" type="button" value="Upload" />
Upvotes: 0