0

I'm trying to save to a SharePoint folder a .pptx file generated using pptxgenjs library. I've generated the blob I need into the console but I haven't been able to save it to the folder once generated.

The script is run on a click event. I'm just including the last bit as the issue is there. I just don't know how to solve it.

var targetUrl = webUrl + "/" + documentLibrary + "/" + folderName;
var FullUrl = webUrl + "/_api/Web/GetFolderByServerRelativeUrl(@target)/Files/add(overwrite=true, url='" + fileName + "')?$expand=ListItemAllFields&@target='" + targetUrl + "'";

function getFileBuffer(uploadFile) {
        var deferred = jQuery.Deferred();
        var reader = new FileReader();
        reader.onloadend = function (e) {
            deferred.resolve(e.target.result);
        }
        reader.onerror = function (e) {
            deferred.reject(e.target.error);
        }
        reader.readAsArrayBuffer(uploadFile);
        return deferred.promise();
    }
function uploadFileToFolder(fileObj, url, success, failure) {
            var apiUrl = FullUrl;
            var getFile = getFileBuffer(fileObj);
            getFile.done(function (arrayBuffer) {
                $.ajax({
                    url: apiUrl,
                    type: "POST",
                    data: arrayBuffer,
                    processData: false,
                    async: false,
                    headers: {
                        "accept": "application/json;odata=verbose",
                        "X-RequestDigest": jQuery("#__REQUESTDIGEST").val(),
                    },
                    success: function (data) {
                        console.log(data);
                        //success(data);
                    },
                    error: function (data) {
                        console.log(data);
                        //failure(data);
                    }
                });
            });
        }
        pptx.save('jszip', function(file1) {
             var newblob = file1;   
        getFileBuffer(newblob);
        }, 'blob');

The .pptx should be generated and saved to the provided URL. I don't want the user to download the pptx file or do anything else. At the moment I get the download window with the pptx file working fine but in console, I get the following error: Uncaught (in promise) TypeError: Failed to execute 'readAsArrayBuffer' on 'FileReader': parameter 1 is not of type 'Blob'.

Any help would be much appreciated!

NAOS
  • 13
  • 5

0 Answers0