The code was working perfectly and suddenly this error:

"Request failed with error message - File Not Found. Stack Trace - undefined"

comes out, can some please help me?

    this.filename = event.target.files[0].name;
    this.selectedFile = event.target.files[0];
    const reader = new FileReader();
    reader.onload = (e) =>
        this.upload(reader.result, this.filename);
    reader.onerror = (e) =>

upload(aB, fileName)
    const bytes = new Uint8Array(aB);
    let i;
    let length;
    let out = '';
    for (i = 0, length = bytes.length; i < length; i += 1)
      out += String.fromCharCode(bytes[i]);
    this.base64 = btoa(out);

    // this.spinner.show();
    let attachmentFiles;
    // @ts-ignore
    const clientContext = new SP.ClientContext(`https://${window.location.host}/sites/spec-dev/portal/`);
    let oWeb = clientContext.get_web();

    // Get list and Attachment folder where the attachment of a particular list item is stored
    const oList = oWeb.get_lists().getByTitle('Reviews');
    const attachmentFolder = oWeb.getFolderByServerRelativeUrl('Lists/Reviews/Attachments/' + this.all[0].ID);
    // @ts-ignore
    const createInfo = new SP.FileCreationInformation();

    attachmentFiles = attachmentFolder.get_files().add(createInfo);

    clientContext.executeQueryAsync(this.QuerySuccess, this.QueryFailure);

This is code I am using to upload file to SharePoint List (Attachment).

  • how is this all[]-array filled / what does it contain? How do you check that the ID you are using in the getFolderByServerRelativeUrl call still exists? Error message looks like that the item with a certain ID cannot be found... – Celophysis Oct 11 '19 at 7:52
  • Thanks man, the id was the issue – Harrish Oct 14 '19 at 5:02
  • Hi @Celophysis the actual issue is with the attachment folder in Sharepoint, the error was shown because tat item in the list didn't have the attachment folder yet created, It seems like at least one attachment has to be uploaded to create the attachment folder in Sharepoint. – Harrish Oct 14 '19 at 7:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.