I want to Upload a file inside a folder using the REST API. Also if the Folder which I have passed is not there then we need to create the folder and then upload the file. Is this really achievable?

Your feedback and suggestions are much appreciated.

1 Answer 1


These snippets should help you I guess. It's done for images but you can easyly adapt it to other fileformats I hope

   * create attachment for an Listitem from a imageURL
   * @param item where the image will be attached
   * @param imageName filename of image
   * @param url image source
  private _appendImage(item, imageName, url): Promise<any> {
    return this._getArrayBufferImage(url).then((result) => {
      return item.attachmentFiles.add(imageName, result).then(v => {


   * fetches a image from an URL as ArrayBuffer
   * @param imageUrl image source
  private async _getArrayBufferImage(imageUrl: string): Promise<any> {
    var res = await fetch(imageUrl, {
      credentials: 'same-origin'
    var blob = await res.blob();
    return new Promise((resolve, reject) => {
      var reader = new FileReader();
      reader.addEventListener("load", () => {
      }, false);
      reader.onerror = () => {
        return reject(this);


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.