附件到共享列表

时间:2020-05-08 12:00:03

标签: file-upload spfx

我是sharepoint的新手,正在尝试关注某个主题 SPFx uploading and adding attachment to a list 在此论坛中将文件附加到共享列表。但是我无法附加文件 进入列表。

这是我的tsx部分:

           <Label for="Documentation">
              <strong>Documentation</strong>
           </Label>
           <Input type="file" name="myfile" id="fileUploadInput" />
           <FormText>
              Please attach the documentation for your Best Practice.
           </FormText>

这是我的WEBPART TS;

            ReactDom.render(element, this.domElement);
            this.setButtonsEventHandlers();
            }

            private setButtonsEventHandlers(): void {
            let fileUpload = document.getElementById("fileUploadInput");
             if (fileUpload) {
             fileUpload.addEventListener("change", () => {
            this.uploadFiles(fileUpload);
           });
           }            
          }

         private async uploadFiles(fileUpload) {
         let file = fileUpload.files[0];
        //let attachmentsArray = this.state.attachmentsToUpload;
         let item = sp.web.lists
         .getByTitle("Best_Practice_Logging")
         .items.getById(15);
          item.attachmentFiles.add(file.name, file).then(v => {
          console.log(v);
          alert("File uploaded");
           });
         //let attachmentUpload = await _listItem.attachmentFiles.add(file.name,file)
           }

0 个答案:

没有答案