I used readasarraybuffer to read the input image and changed the array to base64 format. Then I used rest api post to upload the image to sharepoint image library, and image got uploaded but it is empty (0 kb) showing white document icon.

  • 2
    You need to show all of your code. You now ask "Yo, guys, my car doesn't go forward, what is wrong?" Commented Feb 2, 2017 at 11:28

1 Answer 1


To upload an image or a file to SharePoint with Full rest you have to pass an array buffer not a base64 string.

var getFile = getFileBuffer(v);
getFile.done(function (arrayBuffer) {
    getFile.done(function (arrayBuffer) {
    var doUpload = uploadDocument(arrayBuffer, fileName);
    doUpload.done(function (file, status, xhr) {
        //the rest of the magic

function uploadDocument(buffer, fileName) {
    var url = _spPageContextInfo.webAbsoluteUrl + '/_api/web/Lists/GetbyTitle(\'your_library\')/RootFolder/Files/add(url=@TargetFileName,overwrite=\'true\')?' +
        '&@TargetFileName=\'' + encodeURI(fileName) + '\'';
    var call = $.ajax({
        url: url,
        type: 'POST',
        data: buffer, //<-- This is the file
        processData: false,
        headers: {
            Accept: 'application/json;odata=verbose',
            'X-RequestDigest': $('#__REQUESTDIGEST').val()
    return call;

function getFileBuffer(v) {
    var deferred = jQuery.Deferred();
    var reader = new FileReader();
    reader.onloadend = function (e) {
    reader.onerror = function (e) {
    return deferred.promise();

The code above is what I use to upload heavy documents to SharePoint. I hope it helps you :)

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.