Code Monkey home page Code Monkey logo

spsave's Introduction

spsave

NPM npm version

Need help on SharePoint with Node.JS? Join our gitter chat and ask question! Gitter chat

Nodejs module for saving files in SharePoint:

  • SharePoint 2013, 2016
  • SharePoint Online

spsave depends heavily on another module sp-request and use it to send REST queries to SharePoint. sp-request, in turns, depends on the module responsible for SharePoint authentiation from node js - node-sp-auth.
CHANGELOG


How to use:

Install:

npm install spsave --save-dev

Usage:

var spsave = require("spsave").spsave;

spsave(coreOptions, creds, fileOptions)
.then(successHandler)
.catch(errorHandler);

Using with gulp

You have following options:

  1. Use official gulp plugin for spsave - gulp-spsave

  2. Use spsave inside gulp tasks or in watchers like this:

     var spsave = require("spsave").spsave;
     
     gulp.task('spsave', function(cb) {
         
       spsave(coreOptions, creds, fileOptions)
       .then(function(){
           cb();
       }).catch(cb);
       
     );
    
  3. Use both approaches. First one is handy if you are processing files in a stream, for example you need minimize, concatenate and then upload. The second can be used if you want just upload files and that's it.

Using with SharePoint hosted apps (uploading to app web)

Please refer to this page (at the bottom)

options:

Starting from spsave 3.x all options divided by logical categories (in order):

  • core options
  • credentials
  • file(s) options

Core options:

  • siteUrl - required, string url of the site
  • checkin - optional, boolean to allow the files to be checked in/published
  • checkinType - optional number, used when checkin options is true
    • 0 - minor
    • 1 - major
    • 2 - overwrite
    • 3 - nocheckin - special case if you don't want your file to be checked-in on every file upload. In that case you file will remain checked-in after upload and you should either manually upload it, or run spsave again with other checkinType
  • checkinMessage - optional string, you can provide your own checkin message, otherwise default will be used
  • notification - optional boolean, when true, spsave will notify about successful upload using node-notifier module
  • filesMetaData - optional, array of IFileMetaData:
    • fileName - required, string file name
    • metadata - metadata object

Credentials:

spsave 3.x implicitly depends on another module used for SharePoint authentication from node js - node-sp-auth. For spsave credentials param you need to pass exactly the same object, as for node-sp-auth credentialsOptions object. That also means that spsave supports all authentication options supported by node-sp-auth. On Recipes page you can find a bit more samples.
You can also pass a null as credentials, in that case spsave will ask you for credentials and will store your credentials in a user folder in an encrypted manner (everything is handled by node-sp-auth actually).

File(s) options:

File options used to tell spsave how to find\load the file to be uploaded to SharePoint. When one is used, others are ignored. There are three file options supported: file content, glob and vinyl file.

File content options:
  • folder - required string, site-relative url to folder, which will be used to save your file. For example for library http://sp2013/sites/dev/SiteAssets folder will be equal to SiteAssets, SiteAssets/subfolder for sub folder. If the folder doesn't exist, spsave will create that folder and all sub folders if required (full hierarchy)
  • fileName - required, string file name
  • fileContent - required, string or buffer file content (binary files supported, you can do something like this: fileContent: fs.readFileSync('app/img/logo.png'))
Glob options (you can provide a mask to read all or certain files from the file system):
  • glob - required, string or string array, i.e. 'build/css/style.css' or ['build/css/*.*']. Pattern is similar to node-glob module.
  • base - optional string, if you want to preserve folders structure inside SharePoint folder, you can provide a base for you files. For example when using glob ['build/css/*.*'] and base: 'build', all css files will be loaded under [SharePoint folder]/css
  • folder - optional string, site-relative url to folder, which will be used to save your file. The same as for file content options. If the folder is null or empty, spsave will try to resolve folder using base option provided
Vinyl options. If you are familiar with vinyl and vinyl-fs you can provide vinyl file directly:
  • file - required, vinyl File object
  • folder - optional string, site-relative url to folder, which will be used to save your file. The same as for file content options. If the folder is null or empty, spsave will try to resolve the folder using base of vinyl file

Don't be scared and confused with a lot of options and take a look at the Recipes page. You can find all possible scenarios with spsave, input params and expected output.

successHandler

Handler gets called upon successful file upload.

errorHandler

Handler gets executed in case of exception inside spsave. Accepts error object as first argument for callback.

Samples

Use Recipes page to see all different options available with spsave.

Basic usage:

var coreOptions = {
    siteUrl: '[sp url]',
    notification: true,
    checkin: true,
    checkinType: 1
};
var creds = {
    username: '[username]',
    password: '[password]',
    domain: '[domain (on premise)]'
};

var fileOptions = {
    folder: 'SiteAssets',
    fileName: 'file.txt',
    fileContent: 'hello world'
};
spsave(coreOptions, creds, fileOptions)
.then(function(){
    console.log('saved');
})
.catch(function(err){
    console.log(err);
});

Development:

I recommend using VS Code for development. Repository already contains some settings for VS Code editor. Before creating Pull Request you need to create an appropriate issue and reference it from PR.

  1. git clone https://github.com/s-KaiNet/spsave.git
  2. cd spsave
  3. git checkout -b myfeature dev
  4. npm run build - restores dependencies and runs typescript compilation
  5. gulp live-dev - setup watchers and automatically runs typescript compilation, tslint and tests when you save files

Tests:

  1. npm test. As a result /reports folder will be created with test results in junit format and code coverage. Additionally test reports will be available in a console window.

Integration testing:

  1. Rename file /test/integration/config.sample.ts to config.ts.
  2. Update information in config.ts with appropriate values (urls, credentials, environment).
  3. Run gulp test-int.

spsave's People

Contributors

dimkk avatar higocidario avatar lafe avatar marc3218 avatar s-kainet avatar viktorhofer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

spsave's Issues

NTLM handshakes are failing with httpntlm repo

Hello,

There is an issue with the httpntlm module that sp-request is using to make the ntlm handshake.

Specifically, the type1 and type3 ntlm hashes that it is creating. To confirm this issue i make requests via the unadulterated "request" module and called the createType1message / createType3message functions directly from the httpntlm/ntlm module.

This does not work.

I used a the ntlmrequest and ntlm module itself from the "node-ntlm-client" and i was able to successfully establish (on premise), ntlm handshakes.

I suggest you use that library.

Issue with UTF-8 characters

I'm using gulp-spsave, and encountered with file encoding.
I've got a simple .html file that is encoded as UTF-8 (also tried UTF-8 with BOM), and umlaut characters, e.g. "Ü" or "Ä". For example, the string Tatsächlich becomes Tatsächlich after the file upload. If I copy the file contents manually inside sharepoint designer, the characters render correctly. Is this a problem of spsave or of how sharepoint managed html file uploads?

Custom Metadata not updated

Hi there,

Trying to update some custom metadata with a glob. Here are my options:

saveOptions = {
    glob: 'xml/pet 123122.xml',
    notification: true,
    folder: '/Pet%2097%20Archive',
    filesMetaData: [{
        metadata: {
            '__metadata':{type:'SP.Data.Pet_x0020_97_x0020_ArchiveItem'},
            'Pet Name': 'Doggy McDogFace',
            'Pet ID#': '666',
            'Title':'McDogFace is awesome'
        }
    }]
}

The file uploads just fine, but Pet Name, ID and title don't get updated. Not sure I'm doing something wrong. Any help will be greatly appreciated.

Where is saved file

I am testing spsave for automation of uploading files to the SP. I was able to save file but I have no idea where it's now.

[16:34:07] spsave: Creating folder or full folders hierarchy: 'TESTING'
[16:34:08] spsave: test.txt checked out.
[16:34:09] spsave: test.txt successfully uploaded to 'https://.........sharepoint.com/personal/........../TESTING' and checked in. Checkin type: major
saved

Looking through the sahrepoint onedrive webapp interface: files / recent/ shared / recycle bin can't find the created file. Also going on the generated link gives me NOT FOUND

Default credentials

Hello,

thanks for that great module. I'm using it for multiple projects. Currently I always have to specify a username and password when using it in combination with gulp-spsave. Is it possible, if no credentials supplied, use the default one in the http requests?

Thanks,
Viktor

spsave: Error: connect ETIMEDOUT 40.126.1.166:443

Hi im trying to use spsave package but I facing this issue Error: connect ETIMEDOUT which unable to resolve.
My environment details:
OS: Windows 7
code editor: VS Code
installed spsave by npm
I tried to delete auth data file but it didn't help.
I am using corporate internet with proxy configuration and I have set the same proxy to my npm.

C:\Users\A674684\Documents\Workspace>gulp
[19:14:32] Using gulpfile ~\Documents\Workspace\gulpfile.js
[19:14:32] Starting 'watch'...
[19:14:32] Finished 'watch' after 6.61 ms
[19:14:32] Starting 'default'...
[19:14:32] Starting 'js'...
[19:14:32] Starting 'css'...
[19:14:32] Finished 'default' after 23 ms
[node-sp-auth]: reading auth data from C:\Users\A674684\AppData\Roaming\spauth\creds\https___nokia.sharepoint.com_sites_dannytest.json
[19:14:54] spsave: Error occured:
[19:14:54] spsave: Error: connect ETIMEDOUT 40.126.1.166:443

[19:14:54] spsave: Stack trace:

[19:14:54] spsave: RequestError: Error: connect ETIMEDOUT 40.126.1.166:443
at new RequestError (C:\Users\A674684\Documents\Workspace\node_modules\request-promise-core\lib\errors.js:14:15)
at Request.plumbing.callback (C:\Users\A674684\Documents\Workspace\node_modules\request-promise-core\lib\plumbing.js:87:29)
at Request.RP$callback [as _callback] (C:\Users\A674684\Documents\Workspace\node_modules\request-promise-core\lib\plumbing.js:46:31)
at self.callback (C:\Users\A674684\Documents\Workspace\node_modules\request\request.js:185:22)
at Request.emit (events.js:160:13)
at Request.onRequestError (C:\Users\A674684\Documents\Workspace\node_modules\request\request.js:877:8)
at ClientRequest.emit (events.js:160:13)
at TLSSocket.socketErrorListener (_http_client.js:389:9)
at TLSSocket.emit (events.js:160:13)
at emitErrorNT (internal/streams/destroy.js:64:8)
at process._tickCallback (internal/process/next_tick.js:152:19)
From previous event:
at coreRequest (C:\Users\A674684\Documents\Workspace\node_modules\sp-request\lib\src\core\SPRequest.js:22:16)
at spRequestFunc (C:\Users\A674684\Documents\Workspace\node_modules\sp-request\lib\src\core\SPRequest.js:69:20)
at Function.spRequestFunc.(anonymous function) [as get] (C:\Users\A674684\Documents\Workspace\node_modules\sp-request\lib\src\core\SPRequest.js:109:24)
at FileSaver.getFileByUrl (C:\Users\A674684\Documents\Workspace\node_modules\spsave\lib\src\core\FileSaver.js:211:31)
at C:\Users\A674684\Documents\Workspace\node_modules\spsave\lib\src\core\FileSaver.js:176:19
From previous event:
at FileSaver.checkoutFile (C:\Users\A674684\Documents\Workspace\node_modules\spsave\lib\src\core\FileSaver.js:171:23)
at FileSaver.saveFile (C:\Users\A674684\Documents\Workspace\node_modules\spsave\lib\src\core\FileSaver.js:51:35)
at FileSaver.save (C:\Users\A674684\Documents\Workspace\node_modules\spsave\lib\src\core\FileSaver.js:38:18)
at saveSingleFile (C:\Users\A674684\Documents\Workspace\node_modules\spsave\lib\src\core\SPSave.js:80:76)
at C:\Users\A674684\Documents\Workspace\node_modules\spsave\lib\src\core\SPSave.js:41:13
From previous event:
at spsave (C:\Users\A674684\Documents\Workspace\node_modules\spsave\lib\src\core\SPSave.js:13:12)
at DestroyableTransform.uploadFile [as _transform] (C:\Users\A674684\Documents\Workspace\node_modules\gulp-spsave\index.js:43:7)
at DestroyableTransform.Transform._read (C:\Users\A674684\Documents\Workspace\node_modules\gulp-spsave\node_modules\readable-stream\lib_stream_transform.js:159:10)
at DestroyableTransform.Transform._write (C:\Users\A674684\Documents\Workspace\node_modules\gulp-spsave\node_modules\readable-stream\lib_stream_transform.js:147:83)
at doWrite (C:\Users\A674684\Documents\Workspace\node_modules\gulp-spsave\node_modules\readable-stream\lib_stream_writable.js:313:64)
at writeOrBuffer (C:\Users\A674684\Documents\Workspace\node_modules\gulp-spsave\node_modules\readable-stream\lib_stream_writable.js:302:5)
at DestroyableTransform.Writable.write (C:\Users\A674684\Documents\Workspace\node_modules\gulp-spsave\node_modules\readable-stream\lib_stream_writable.js:241:11)
at DestroyableTransform.ondata (C:\Users\A674684\Documents\Workspace\node_modules\through2\node_modules\readable-stream\lib_stream_readable.js:619:20)
at DestroyableTransform.emit (events.js:160:13)
at addChunk (C:\Users\A674684\Documents\Workspace\node_modules\through2\node_modules\readable-stream\lib_stream_readable.js:291:12)
at readableAddChunk (C:\Users\A674684\Documents\Workspace\node_modules\through2\node_modules\readable-stream\lib_stream_readable.js:278:11)
at DestroyableTransform.Readable.push (C:\Users\A674684\Documents\Workspace\node_modules\through2\node_modules\readable-stream\lib_stream_readable.js:245:10)
at DestroyableTransform.Transform.push (C:\Users\A674684\Documents\Workspace\node_modules\through2\node_modules\readable-stream\lib_stream_transform.js:148:32)
at DestroyableTransform._transform (C:\Users\A674684\Documents\Workspace\node_modules\gulp-cached\index.js:43:10)
at DestroyableTransform.Transform._read (C:\Users\A674684\Documents\Workspace\node_modules\through2\node_modules\readable-stream\lib_stream_transform.js:184:10)
at DestroyableTransform.Transform.write (C:\Users\A674684\Documents\Workspace\node_modules\through2\node_modules\readable-stream\lib_stream_transform.js:172:83)
at doWrite (C:\Users\A674684\Documents\Workspace\node_modules\through2\node_modules\readable-stream\lib_stream_writable.js:428:64)
at writeOrBuffer (C:\Users\A674684\Documents\Workspace\node_modules\through2\node_modules\readable-stream\lib_stream_writable.js:417:5)
at DestroyableTransform.Writable.write (C:\Users\A674684\Documents\Workspace\node_modules\through2\node_modules\readable-stream\lib_stream_writable.js:334:11)
at write (C:\Users\A674684\Documents\Workspace\node_modules\vinyl-fs\node_modules\readable-stream\lib_stream_readable.js:623:24)
at flow (C:\Users\A674684\Documents\Workspace\node_modules\vinyl-fs\node_modules\readable-stream\lib_stream_readable.js:632:7)
at DestroyableTransform.pipeOnReadable (C:\Users\A674684\Documents\Workspace\node_modules\vinyl-fs\node_modules\readable-stream\lib_stream_readable.js:664:5)
at DestroyableTransform.emit (events.js:160:13)
at emitReadable
(C:\Users\A674684\Documents\Workspace\node_modules\vinyl-fs\node_modules\readable-stream\lib_stream_readable.js:448:10)
at emitReadable (C:\Users\A674684\Documents\Workspace\node_modules\vinyl-fs\node_modules\readable-stream\lib_stream_readable.js:444:5)
Unhandled rejection RequestError in plugin 'gulp-spsave'

Invalid characters from CRA js file

I'm attempting to use spsave to save files from CRA build to SharePoint.

The file or folder name \\\"MyProject/static/js/runtime~main.d653cc00.js\\\" contains invalid characters. Please use a different name. Common invalid characters include the following # % & * : < > ? / { | }

I'm assuming it's the tilde - but I believe that's what create-react-app is using these days.
I guess the file is used to load and run the app - https://facebook.github.io/create-react-app/docs/production-build

Getting HTTP 401, SP 2013

Hello!
I was trying to learn some new stuff which is described in this nice article http://julieturner.net/2018/01/conquer-your-dev-toolchain-in-classic-sharepoint-part-2/
But I can't get spsave to work in my environment, I'm getting error 401 =(
Please, can you suggest some ideas how to debug the issue?

Stacktrace:

spsave: StatusCodeError: 401 - "{"error":{"code":"-2147024891, System.UnauthorizedAccessException","message":{"lang":"uk-UA","value":"\u0414\u043e\u0441\u0442\u0443\u043f \u0437\u0430\u0431\u043e\u0440\u043e\u043d\u0435\u043d\u043e. \u0423 \u0432\u0430\u0441 \u043d\u0435\u043c\u0430\u0454 \u0434\u043e\u0437\u0432\u043e\u043b\u0456\u0432 \u043d\u0430 \u0432\u0438\u043a\u043e\u043d\u0430\u043d\u043d\u044f \u0446\u0456\u0454\u0457 \u0434\u0456\u0457 \u0430\u0431\u043e \u043d\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u0434\u043e \u0446\u044c\u043e\u0433\u043e \u0440\u0435\u0441\u0443\u0440\u0441\u0443."},"innererror":{"message":"0x80070005\u041d\u0435\u043c\u0430\u0454 \u0434\u043e\u0441\u0442\u0443\u043f\u0443.","type":"System.UnauthorizedAccessException","stacktrace":" at Microsoft.SharePoint.SPGlobal.HandleUnauthorizedAccessException(UnauthorizedAccessException ex)\r\n at Microsoft.SharePoint.Library.SPRequest.PutFile(String bstrUrl, String bstrWebRelativeUrl, Object punkFile, Int64 cbFile, Object punkSPFileMgr, Object punkFFM, Int64 PutFileOpt, String bstrCreatedBy, String bstrModifiedBy, Int32 iCreatedByID, Int32 iModifiedByID, Object varTimeCreated, Object varTimeLastModified, Object varProperties, String bstrCheckinComment, String bstrLockIdMatch, String bstEtagToMatch, Int32 lockType, String lockId, Int32 minutes, Int32 fRefreshLock, Int32 bValidateReqFields, Guid gNewDocId, SPFileSaveParams sfsp, SPFileInfo& pFileProps, UInt32& pdwVirusCheckStatus, String& pVirusCheckMessage, String& pEtagReturn, Byte& piLevel, Int32& pbIgnoredReqProps)\r\n at Microsoft.SharePoint.SPFileCollection.AddStreamOrBytesInternal(String urlOfFile, Stream file, Int64 fileSizeToSave, SPFileStreamManager spmgr, PutFileOpt fileOpt, String createdBy, String modifiedBy, Int32 createdByID, Int32 modifiedByID, DateTime timeCreated, DateTime timeLastModified, Object varProperties, String checkInComment, Stream formatMetadata, String lockIdMatch, String etagToMatch, SPLockType lockType, String lockId, TimeSpan lockTimeout, Boolean validateRequiredFields, SPVirusCheckStatus& virusCheckStatus, String& virusCheckMessage, String& etagNew, Boolean& ignoredRequiredProps)\r\n at Microsoft.SharePoint.SPFileCollection.Add(String urlOfFile, Stream file, Boolean overwrite, String checkInComment, Boolean checkRequiredFields)\r\n at Microsoft.SharePoint.SPFileCollection.Add(SPFileCreationInformation parameters)\r\n at Microsoft.SharePoint.Client.ServerStub.InvokeMethodWithMonitoredScope(Object target, String methodName, ClientValueCollection args, ProxyContext proxyContext, Boolean& isVoid)\r\n at Microsoft.SharePoint.Client.Rest.RestRequestProcessor.InvokeMethod(Boolean mainRequestPath, Object value, ServerStub serverProxy, EdmParserNode node, Boolean resourceEndpoint, MethodInformation methodInfo, Boolean isExtensionMethod, Boolean isIndexerMethod)\r\n at Microsoft.SharePoint.Client.Rest.RestRequestProcessor.GetObjectFromPathMember(Boolean mainRequestPath, String path, Object value, EdmParserNode node, Boolean resourceEndpoint, MethodInformation& methodInfo)\r\n at Microsoft.SharePoint.Client.Rest.RestRequestProcessor.GetObjectFromPath(Boolean mainRequestPath, String path, String pathForErrorMessage)\r\n at Microsoft.SharePoint.Client.Rest.RestRequestProcessor.Process()\r\n at Microsoft.SharePoint.Client.Rest.RestRequestProcessor.ProcessRequest()\r\n at Microsoft.SharePoint.Client.Rest.RestService.ProcessQuery(Stream inputStream, IList`1 pendingDisposableContainer)"}}}"
at new StatusCodeError (/media/user/data/tasks/dev/sp-pnp/demos/test/node_modules/request-promise-core/lib/errors.js:32:15)
at Request.plumbing.callback (/media/user/data/tasks/dev/sp-pnp/demos/test/node_modules/request-promise-core/lib/plumbing.js:104:33)
at Request.RP$callback [as _callback] (/media/user/data/tasks/dev/sp-pnp/demos/test/node_modules/request-promise-core/lib/plumbing.js:46:31)
at Request.self.callback (/media/user/data/tasks/dev/sp-pnp/demos/test/node_modules/request/request.js:185:22)
at emitTwo (events.js:126:13)
at Request.emit (events.js:214:7)
at Request. (/media/user/data/tasks/dev/sp-pnp/demos/test/node_modules/request/request.js:1157:10)
at emitOne (events.js:116:13)
at Request.emit (events.js:211:7)
at IncomingMessage. (/media/user/data/tasks/dev/sp-pnp/demos/test/node_modules/request/request.js:1079:12)
at Object.onceWrapper (events.js:313:30)
at emitNone (events.js:111:20)
at IncomingMessage.emit (events.js:208:7)
at endReadableNT (_stream_readable.js:1064:12)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
From previous event:
at coreRequest (/media/user/data/tasks/dev/sp-pnp/demos/test/node_modules/sp-request/lib/src/core/SPRequest.js:22:16)
at spRequestFunc (/media/user/data/tasks/dev/sp-pnp/demos/test/node_modules/sp-request/lib/src/core/SPRequest.js:69:20)
at Function.spRequestFunc.(anonymous function) [as post] (/media/user/data/tasks/dev/sp-pnp/demos/test/node_modules/sp-request/lib/src/core/SPRequest.js:109:24)
at /media/user/data/tasks/dev/sp-pnp/demos/test/node_modules/spsave/lib/src/core/FileSaver.js:57:36
at runCallback (timers.js:794:20)
at tryOnImmediate (timers.js:752:5)
at processImmediate [as _immediateCallback] (timers.js:729:5)
From previous event:
at FileSaver.saveFile (/media/user/data/tasks/dev/sp-pnp/demos/test/node_modules/spsave/lib/src/core/FileSaver.js:56:14)
at FileSaver.save (/media/user/data/tasks/dev/sp-pnp/demos/test/node_modules/spsave/lib/src/core/FileSaver.js:38:18)
at saveSingleFile (/media/user/data/tasks/dev/sp-pnp/demos/test/node_modules/spsave/lib/src/core/SPSave.js:80:76)
at /media/user/data/tasks/dev/sp-pnp/demos/test/node_modules/spsave/lib/src/core/SPSave.js:41:13
From previous event:
at spsave (/media/user/data/tasks/dev/sp-pnp/demos/test/node_modules/spsave/lib/src/core/SPSave.js:13:12)
at /media/user/data/tasks/dev/sp-pnp/demos/test/gulpfile.js:45:25
at wrappedMapper (/media/user/data/tasks/dev/sp-pnp/demos/test/node_modules/map-stream/index.js:83:19)
at Stream.stream.write (/media/user/data/tasks/dev/sp-pnp/demos/test/node_modules/map-stream/index.js:95:21)
at TaskProxy._runProxiedTask (/media/user/data/tasks/dev/sp-pnp/demos/test/node_modules/gulp-cache/lib/index.js:413:8)
at TaskProxy._runProxiedTaskAndQueueCache (/media/user/data/tasks/dev/sp-pnp/demos/test/node_modules/gulp-cache/lib/index.js:357:15)
at /media/user/data/tasks/dev/sp-pnp/demos/test/node_modules/gulp-cache/lib/index.js:121:10
at Generator.next ()
at step (/media/user/data/tasks/dev/sp-pnp/demos/test/node_modules/babel-runtime/helpers/asyncToGenerator.js:17:30)
at /media/user/data/tasks/dev/sp-pnp/demos/test/node_modules/babel-runtime/helpers/asyncToGenerator.js:28:13
at

My code which does not work:

const spsaveOptions = {
    site: {
        siteUrl: settingsShared.siteCollURL, // like "https://server.domain.com"
        checkinType: 2,
        checkin: false
    },
    creds: {
        domain: settingsPrivate.domain, // like "domain"
        username: settingsPrivate.username, // like "username"
        password: settingsPrivate.password // like "password"
    }
};

gulp.task("copyToSharePointFolder",
    function () {
        gulp.src(settingsShared.srcFiles)
            .pipe(
                cache(
                    map(function (file, cb) {
                        console.log(spsaveOptions.creds);
                        spsave(spsaveOptions.site, spsaveOptions.creds, {
                            file: file,
                            folder: settingsShared.destFolder
                        }).then(function () {
                            cb(null, file);
                        }).catch(function () {
                            console.log(arguments);
                        });
                    }),
                    { key: makeHashKey }
                )
            );
    }
);

Also I tried this code and it works:

var spauth = require('node-sp-auth');
var reqpromise = require('request-promise');

gulp.task("sptest", function () {
    spauth
        .getAuth(spsaveOptions.site.siteUrl, {
            username: spsaveOptions.creds.username,
            password: spsaveOptions.creds.password,
            domain: spsaveOptions.creds.domain
        })
        .then(data => {
            let headers = data.headers;
            headers['Accept'] = 'application/json;odata=verbose';
            let requestOpts = data.options;
            requestOpts.json = true;
            requestOpts.headers = headers;
            requestOpts.url = spsaveOptions.site.siteUrl + '/_api/web';

            reqpromise.get(requestOpts).then(response => {
                console.log(response.d);
            });
        });
});

So what could be possible wrong with the first piece of code?

Thank you!

Works on Windows but 401 on OSX

Hello,

I am trying to get spsave to work on OSX for an on-premise & NTLM authentication.

It works fine with Windows but I am getting a "401 - undefined" running the same Node.js code on a MacBook Pro.

Is there something I need to configure on OSX to get NTLM auth to work.
It seems spsace create a "Authentication" header with "NTLM ......" but fails on the POST to get /_api/contextinfo

Got error when trying to get access token in nodejs using azure, AADSTS50058: A silent sign-in request was sent but no user is signed in

I am trying to implement azure login in nodejs scheduler app, and then want to upload file to share point.
First i need to login, then get access token,refresh token, admin access token etc.
When i try to get access token , i got error like this.
Here no use of any front end.

URL= 'https://login.microsoftonline.com/' + TENANT_ID + '/oauth2/token',
Status Code Error: 400 -
"{"error":"invalid_grant","error_description":"AADSTS50058: A silent sign-in request was sent but no user is signed in.\r\nTrace ID: 05db5c6a-155c-4870-9bca-a518b5931900\r\nCorrelation ID: 1e8372d0-c1ba-4070-88d7-597e9cb5cb2c\r\nTimestamp: 2019-08-14 12:04:42Z","error_codes":[50058],"timestamp":"2019-08-14 12:04:42Z","trace_id":"05db5c6a-155c-4870-9bca-a518b5931900","correlation_id":"1e8372d0-c1ba-4070-88d7-597e9cb5cb2c","error_uri":"https://login.microsoftonline.com/error?code=50058\"}"

Here the code

async function init(parsedBody) {
var jwtToken = await sharepointAuth.getJWTToken(parsedBody);
console.log("jwtToken:",jwtToken)
const config = {
JWK_URI: appConstants.JWK_URI,
ISS: appConstants.ISS,
AUD: appConstants.conf.AUD,
};
console.log(config)
await azureJWT.verify(jwtToken, config).then(async () => {
console.log("----------------------------------")
var fileName = 'analytics.min.js';
var filePath = './public/analytics.min.js';
var userAccessToken = await getAccessToken(jwtToken);
console.log("userAccessToken:", userAccessToken);
var accessTokenObj = await sharepointAuth.getAdminAccessToken();
accessToken = accessTokenObj.access_token;
console.log("accessToken:", accessToken)
fs.readFile(filePath, { encoding: null }, function (err, data) {
const relativeUrl = web/GetFolderByServerRelativeUrl('${selectedFolderName}');
const SHAREPOINT_HEADER = {
'Authorization': Bearer ${accessToken},
"Content-Type": application/json;odata=verbose,
'Accept': 'application/json;odata=verbose',
}
const options = {
method: "POST",
uri: ${SHAREPOINT_URI}${relativeUrl}/Files/add(url='${fileName}',overwrite=true),
headers: SHAREPOINT_HEADER,
body: data
};
console.log(options)
rp(options)
.then(() => {
// POST succeeded...
console.log('File uploaded!');
})
.catch((error) => {
// POST failed...
console.log("File Upload Error: ", error.toString());
});
});
});
}
const request = require("request");
const endpoint = "https://login.microsoftonline.com/tenentId/oauth2/token";
const requestParams = {
grant_type: "client_credentials",
client_id: "ClientId",
client_secret: "Secret",
resource: "ClientId"
};

request.post({ url: endpoint, form: requestParams }, function (err, response, body) {
if (err) {
console.log("error");
}
else {
console.log("Body=" + body);
let parsedBody = JSON.parse(body);
if (parsedBody.error_description) {
console.log("Error=" + parsedBody.error_description);
}
else {
console.log("parsedBody : " + parsedBody);
console.log("Access Token=" + parsedBody.access_token);
init(parsedBody);
}
}
});

function getAccessToken(jwtToken) {
return new Promise(async (resolve) => {
try {
const options = {
method: 'POST',
uri: URL,
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
formData: {
grant_type: appConstants.OTB_GRANT_TYPE,
client_id: appConstants.conf.AUD,
client_secret: appConstants.conf.CLIENT_SECRET,
resource: appConstants.OTB_RESOURCE_URI2,
client_assertion_type: appConstants.OTB_CLIENT_ASSERTION_TYPE,
requested_token_use: appConstants.OTB_REQ_TOKEN_USE,
scope: appConstants.OTB_SCOPE,
assertion: jwtToken,
},
};
console.log("options:", options)
await rp(options)
.then(async (parsedBody) => {
// POST succeeded...
const result = JSON.parse(parsedBody);
console.log("****************************************** result", result)
refreshToken = result.refresh_token;

  resolve(result.access_token);
})
.catch((error) => {
  // POST failed...
  console.log('getAccessTokenRequestError: ', error.toString());
  resolve(appConstants.ACCESS_TOKEN_ERROR);
});

} catch (error) {
console.log('getAccessTokenRequestPromiseError: ', error.toString());
resolve(appConstants.MIDDLEWARE_ERROR);
}
});
}
I have no idea about azure login without front end. I want to login in azure and upload file to share point in scheduler app in node.

First i need to login by using client id and secret. then i got bearer token. then i want to get access token by using bearer token. At that time i get error like this.

AADSTS50058: A silent sign-in request was sent but no user is signed in

Preserve folder structure

Hello, tried your util - amazing.

But this one thing which made me sad - flat file structure of my dist folder of gulp-angular yeoman generator in destination folder in SharePoint(

I will try to PR asap, to fill the gap.

Thanks for sharing!

Anouncing spsave 2.0

Long time ago I created this project more like POC, rather then something mature and stable. And, you know, code also looks more like POC.
By now to my surprise many people use spsave or gulp-spsave and it's shame for me to have such code publicly available.

It's time to change. In nearest month project will be rewritten from ground in typescript, with unit testing. More options and features are coming, I'm still thinking about which features may be helpful. If you want something special or know about feature you think is useful, please comment and I will include it.

Upload to root

Is there a way to upload files directly to the site root instead of requiring a folder?
image

@Types/Color causes issues

The @types/colors package has recently been made redundant by the colors package including its own typing. Removing the dependancy solves the issue

TS2717: Subsequent property declarations must have the same type. Property 'bold' must be of type '() => string', but here has type 'string'.

Successful upload message

Hello, is there a way to change the default message when the file is successfully uploaded or entirely remove it??
[18:06:18] spsave: test3.csv successfully uploaded to 'https://..............'

unable to set page layout associate content type

I was trying to deploy a page layout and i need to set the property of the associated content type.
https://www.screencast.com/t/E7S5emQe

I went looking at the object for the field and I don't see it. I'm wondering if you have any recommendations for setting that field value.

Object {odata.metadata: "https://bandrdev.sharepoint.com/_api/$metadata#SP.…ta__x005f_catalogs_x002f_masterpageItems/@Element", odata.type: "SP.Data.OData__x005f_catalogs_x002f_masterpageItem", odata.id: "da0edb91-a388-4f42-b359-2a273a333d11", odata.etag: ""10"", odata.editLink: "Web/Lists(guid'6ce3f20b-1de4-430e-b5f0-effe118aa75e')/Items(3498)"…}
AnonymousCacheProfileId
:
null
AuthenticatedCacheProfileId
:
null
AuthorId
:
11
CheckoutUserId
:
null
CompatibleManagedProperties
:
null
CompatibleSearchDataTypes
:
null
ContentTypeId
:
"0x01010007FF3E057FA8AB4AA42FCB67B453FFC100E214EEE741181F4E9F7ACC43278EE81100B1A4769B4017DF41BF9143357A5A55E1"
CrawlerXSLFile
:
null
Created
:
"2017-04-25T19:16:26Z"
DefaultCssFile
:
null
DisplayTemplateJSIconUrl
:
null
DisplayTemplateJSTargetControlType
:
null
DisplayTemplateJSTargetListTemplate
:
null
DisplayTemplateJSTargetScope
:
null
DisplayTemplateJSTemplateHidden
:
null
DisplayTemplateJSTemplateType
:
null
DisplayTemplateLevel
:
null
EditorId
:
11
FileSystemObjectType
:
0
GUID
:
"1eea1b55-51d7-4367-a86a-da24f7434fad"
HtmlDesignAssociated
:
null
HtmlDesignPreviewUrl
:
null
HtmlDesignStatusAndPreview
:
null
ID
:
3498
Id
:
3498
ManagedPropertyMapping
:
null
MasterPageDescription
:
null
Modified
:
"2017-04-25T19:56:49Z"
OData__CopySource
:
null
OData__UIVersionString
:
"0.10"
PublishingAssociatedVariations
:
null
PublishingContactId
:
null
PublishingContactStringId
:
null
PublishingHidden
:
false
PublishingPreviewImage
:
null
ServerRedirectedEmbedUri
:
null
ServerRedirectedEmbedUrl
:
""
TargetControlType
:
null
TemplateHidden
:
null
Title
:
"123123213"
UIVersion
:
null
odata.editLink
:
"Web/Lists(guid'6ce3f20b-1de4-430e-b5f0-effe118aa75e')/Items(3498)"
odata.etag
:
""10""
odata.id
:
"da0edb91-a388-4f42-b359-2a273a333d11"
odata.metadata
:
"https://bandrdev.sharepoint.com/_api/$metadata#SP.ListData.OData__x005f_catalogs_x002f_masterpageItems/@Element"
odata.type
:
"SP.Data.OData__x005f_catalogs_x002f_masterpageItem"

How to reconcile 'removed' files?

Is there a recommended way to have files that exist in the remote location but aren't found in the locally selected files be deleted? If I try to do a folder as replace would that do the trick?

No XML to parse!

I have gotten this working on my sharepoint but moving it to a client space i am getting this error No XML to parse!

node_modules/node-sp-auth/lib/src/utils/AdfsHelper.js:32:23)
    at runCallback (timers.js:794:20)
    at tryOnImmediate (timers.js:752:5)
    at processImmediate [as _immediateCallback] (timers.js:729:5)
From previous event:

I added some debugging to AdsfHelper.js and am getting no response from the following request 404 File Not Found

POST https://login.live.com/adfs/services/trust/13/usernamemixed

    <s:Header>
      <a:Action s:mustUnderstand="1">http://docs.oasis-open.org/ws-sx/ws-trust/200512/RST/Issue</a:Action>
      <a:ReplyTo>
        <a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
      </a:ReplyTo>
      <a:To s:mustUnderstand="1">https://login.live.com/adfs/services/trust/13/usernamemixed</a:To>
      <o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
        <o:UsernameToken u:Id="uuid-ommimtted-token">
          <o:Username>[email protected]</o:Username>
          <o:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">mypassword</o:Password>
        </o:UsernameToken>
      </o:Security>
    </s:Header>
    <s:Body>
      <trust:RequestSecurityToken xmlns:trust="http://docs.oasis-open.org/ws-sx/ws-trust/200512">
        <wsp:AppliesTo xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
          <wsa:EndpointReference xmlns:wsa="http://www.w3.org/2005/08/addressing">
            <wsa:Address>urn:federation:MicrosoftOnline</wsa:Address>
          </wsa:EndpointReference>
        </wsp:AppliesTo>
        <trust:KeyType>http://docs.oasis-open.org/ws-sx/ws-trust/200512/Bearer</trust:KeyType>
        <trust:RequestType>http://docs.oasis-open.org/ws-sx/ws-trust/200512/Issue</trust:RequestType>
      </trust:RequestSecurityToken>
    </s:Body>
  </s:Envelope>```

Error while resolving authentication class

I am getting this error while using SharePoint Online addin only authentication with client id and secret.Where exactly should I pass token i get from spauth. I get this error when I pass headers in coreoptions

TypeError: Cannot read property 'replace' of undefined

I'm receiving the error below. Just to double check, is this caused because of the 'No files were found' message? Can this be safely ignored?

{ message: 'No files were uploaded. No files were found which match your criteria.' } TypeError: Cannot read property 'replace' of undefined at Function.UrlHelper.removeTrailingSlash (C:\Users\stbrunee\gitroot\SPDICT-ERGOPORT\sharepoint\node_modules\spsave\lib\src\utils\UrlHelper.js:7:20) at new FileSaver (C:\Users\stbrunee\gitroot\SPDICT-ERGOPORT\sharepoint\node_modules\spsave\lib\src\core\FileSaver.js:22:58) at saveSingleFile (C:\Users\stbrunee\gitroot\SPDICT-ERGOPORT\sharepoint\node_modules\spsave\lib\src\core\SPSave.js:80:12) at saveFileArray (C:\Users\stbrunee\gitroot\SPDICT-ERGOPORT\sharepoint\node_modules\spsave\lib\src\core\SPSave.js:64:9) at C:\Users\stbrunee\gitroot\SPDICT-ERGOPORT\sharepoint\node_modules\spsave\lib\src\core\SPSave.js:30:13 at spsave (C:\Users\stbrunee\gitroot\SPDICT-ERGOPORT\sharepoint\node_modules\spsave\lib\src\core\SPSave.js:13:12) at distribute (C:\Users\stbrunee\gitroot\SPDICT-ERGOPORT\sharepoint\webpack.config.js:315:5) at Timeout.setTimeout [as _onTimeout] (C:\Users\stbrunee\gitroot\SPDICT-ERGOPORT\sharepoint\webpack.config.js:153:50) at ontimeout (timers.js:498:11) at tryOnTimeout (timers.js:323:5) at Timer.listOnTimeout (timers.js:290:5)

Multi Factor

Its not yet compatible with a sharepoint online site that uses multi factor authentication.

File getting uploaded succesfully but getting error in output Task Runner Window

From @AvniBhatt on June 14, 2016 10:42

File is getting uploaded successfully but getting error in Output Task runner window.
Error:

[16:06:17] Using gulpfile ~\documents\visual studio 2013\Projects\GulpTask\gulpfile.js
[16:06:17] Starting 'concat-js'...
[16:06:17] Finished 'concat-js' after 8.81 ms
[16:06:17] Starting 'minify-js'...
[16:06:17] Finished 'minify-js' after 5.21 ms
[16:06:17] Starting 'upload-to-sp'...
[16:06:17] Finished 'upload-to-sp' after 3.29 ms
[16:06:20] spsave: GulpDemo.js checked out.
[16:06:20] spsave: GulpDemo.js successfully uploaded to '<>/TestDocLib' and checked in. Checkin type: minor
[16:06:20] spsave: Error occured:
[16:06:20] spsave: Error: Argument error, options.body.

[16:06:20] spsave: Stack trace:

[16:06:20] spsave: RequestError: Error: Argument error, options.body.
    at new RequestError (<PATH>\node_modules\gulp-spsave\node_modules\spsave\node_modules\sp-request\node_modules\request-promise\lib\errors.js:14:15)
    at Request.RP$callback [as _callback] (<PATH>\node_modules\gulp-spsave\node_modules\spsave\node_modules\sp-request\node_modules\request-promise\lib\rp.js:60:25)
    at self.callback (<PATH>\node_modules\gulp-spsave\node_modules\spsave\node_modules\sp-request\node_modules\request\request.js:200:22)
    at emitOne (events.js:77:13)
    at Request.emit (events.js:169:7)
    at setContentLength (<PATH>\node_modules\gulp-spsave\node_modules\spsave\node_modules\sp-request\node_modules\request\request.js:452:14)
    at Request.init (<PATH>\node_modules\gulp-spsave\node_modules\spsave\node_modules\sp-request\node_modules\request\request.js:457:5)
    at Request.RP$initInterceptor [as init] (<PATH>\node_modules\gulp-spsave\node_modules\spsave\node_modules\sp-request\node_modules\request-promise\lib\rp.js:137:25)

Code:

gulp.task('upload-to-sp', ['minify-js'], function () {
    gulp.src("./Output/*.js")
      .pipe(spsave({
          username: "<UNAME>",
          password: "<PASSWORD>",
          siteUrl: "<URL>",
          folder: "<FOLDER>",
          checkin: true
      }));
});

Note:
This issue happens randomly. And occurs during successive builds. For first build, it uploads successfully. During successive builds, it randomly generates this error and file remains checked-out upon process termination.

If I delete the file again and re-build, it successfully uploads.

Copied from original issue: s-KaiNet/gulp-spsave#10

Upload files > 250 MB

I was trying to upload a relatively big file (600MB) but an error saying that the file is too big to be uploaded.

Is there any way to do so?

Unexpected error started to show up

All was working until now. Can't seem to find the cause of this...

[10:06:43] spsave: Error occured:
[10:06:43] spsave: Unexpected close tag
Line: 7
Column: 7
Char: >

Support for Custom HTTP Headers / Mixed Mode Authentication

Hello @s-KaiNet!

First: Thank you for authoring spsave! I am using this library as part of my VSCode addon: SPGo (https://github.com/readysitego/spgo) and it has saved me hours of work.

A number of my users support SharePoint environments where mixed mode authentication is used, but are unable to authenticate using NTLM Credentials due to the requirement that the "X-FORMS_BASED_AUTH_ACCEPTED” header be present, with a value of "f" (this configuration forces SharePoint to use NTLM auth).

Can you extend the spsave() function to also optionally accept a set of headers to include in all http/s calls to the SharePoint server?

Thanks!
Chris

'undefined is not a function' at getFolderPathsArray

I get this error not matter how I specify the src...
I use gulp-spsave and have exactly the same task working in another project that uses the previous version of spsave. Do I have to specify the source differently now?

My task is...

gulp.task("deploy-mainsite-siteassets", function () {

    console.log("User: " + config.username);

    return gulp
        .src("./MainSite/SiteAssets/**/*.*")
        .pipe(spsave({
            username: config.username,
            password: config.password,
            siteUrl: confug.url,
            folder: "SiteAssets",
            flatten: false
        }));

});

The full error is...

[Projectfolder]\node_modules\gulp-spsave\node_modules\spsave\lib\folders.js:107
        if(folder.endsWith("/") && folder !== "/"){
                  ^
TypeError: undefined is not a function
    at getFolderPathsArray ([Projectfolder]\node_modules\gulp-spsave\node_modules\spsave\lib\folders.js:107:12)
    at Object.checkAndCreateIfNotExist ([Projectfolder]\node_modules\gulp-spsave\node_modules\spsave\lib\folders.js:12:21)
    at uploadFile ([Projectfolder]\node_modules\gulp-spsave\node_modules\spsave\lib\spsave.js:151:11)
    at [Projectfolder]\node_modules\gulp-spsave\node_modules\spsave\lib\spsave.js:71:5
    at [Projectfolder]\node_modules\gulp-spsave\node_modules\spsave\lib\spsave.js:100:5
    at finalCallback ([Projectfolder]\node_modules\gulp-spsave\node_modules\spsave\node_modules\httpreq\lib\httpreq.js:111:4)
    at IncomingMessage.<anonymous> ([Projectfolder]\node_modules\gulp-spsave\node_modules\spsave\node_modules\httpreq\lib\httpreq.js:343:5)
    at IncomingMessage.emit (events.js:129:20)
    at _stream_readable.js:908:16
    at process._tickCallback (node.js:355:11)

will it work through vpn

I'm working at a client that is using a vpn to connect to SP. I'm current offsite trying to push using SPSave and getting an error:

[14:34:52] Starting 'push'...
[14:34:54] spsave: Error occured:
[14:34:54] spsave: 401 - undefined

[14:34:54] spsave: Stack trace:

[14:34:54] spsave: StatusCodeError: 401 - undefined
    at new StatusCodeError (C:\Users\me\Downloads\x\node_modules\request-promise-core\lib\errors.js:32:15)
    at Request.plumbing.callback (C:\Users\me\Downloads\x\node_modules\request-promise-core\lib\plumbing.js:104:33)
    at Request.RP$callback [as _callback] (C:\Users\me\Downloads\x\node_modules\request-promise-core\lib\plumbing.js:46:31)
    at Request.self.callback (C:\Users\me\Downloads\x\node_modules\request\request.js:185:22)
    at emitTwo (events.js:126:13)
    at Request.emit (events.js:214:7)
    at Request.<anonymous> (C:\Users\me\Downloads\x\node_modules\request\request.js:1161:10)
    at emitOne (events.js:116:13)
    at Request.emit (events.js:211:7)
    at IncomingMessage.<anonymous> (C:\Users\me\Downloads\x\node_modules\request\request.js:1083:12)
    at Object.onceWrapper (events.js:313:30)
    at emitNone (events.js:111:20)
    at IncomingMessage.emit (events.js:208:7)
    at endReadableNT (_stream_readable.js:1064:12)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)
From previous event:
    at coreRequest (C:\Users\me\Downloads\x\node_modules\sp-request\lib\src\core\SPRequest.js:22:16)
    at spRequestFunc (C:\Users\me\Downloads\x\node_modules\sp-request\lib\src\core\SPRequest.js:69:20)
    at Function.spRequestFunc.(anonymous function) [as post] (C:\Users\me\Downloads\x\node_modules\sp-request\lib\src\core\SPRequest.js:109:24)
    at C:\Users\me\Downloads\x\node_modules\sp-request\lib\src\core\SPRequest.js:87:27
From previous event:
    at Function.spRequestFunc.requestDigest (C:\Users\me\Downloads\x\node_modules\sp-request\lib\src\core\SPRequest.js:79:16)
    at C:\Users\me\Downloads\x\node_modules\spsave\lib\src\core\FileSaver.js:54:36
    at runCallback (timers.js:810:20)
    at tryOnImmediate (timers.js:768:5)
    at processImmediate [as _immediateCallback] (timers.js:745:5)
From previous event:
    at FileSaver.saveFile (C:\Users\me\Downloads\x\node_modules\spsave\lib\src\core\FileSaver.js:53:14)
    at FileSaver.save (C:\Users\me\Downloads\x\node_modules\spsave\lib\src\core\FileSaver.js:38:18)
    at saveSingleFile (C:\Users\me\Downloads\x\node_modules\spsave\lib\src\core\SPSave.js:80:76)
    at C:\Users\me\Downloads\x\node_modules\spsave\lib\src\core\SPSave.js:41:13
From previous event:
    at spsave (C:\Users\me\Downloads\x\node_modules\spsave\lib\src\core\SPSave.js:13:12)
    at DestroyableTransform.uploadFile [as _transform] (C:\Users\me\Downloads\x\node_modules\gulp-spsave\index.js:42:7)
    at DestroyableTransform.Transform._read (C:\Users\me\Downloads\x\node_modules\gulp-spsave\node_modules\readable-stream\lib\_stream_transform.js:159:10)
    at DestroyableTransform.Transform._write (C:\Users\me\Downloads\x\node_modules\gulp-spsave\node_modules\readable-stream\lib\_stream_transform.js:147:83)
    at doWrite (C:\Users\me\Downloads\x\node_modules\gulp-spsave\node_modules\readable-stream\lib\_stream_writable.js:313:64)
    at writeOrBuffer (C:\Users\me\Downloads\x\node_modules\gulp-spsave\node_modules\readable-stream\lib\_stream_writable.js:302:5)
    at DestroyableTransform.Writable.write (C:\Users\me\Downloads\x\node_modules\gulp-spsave\node_modules\readable-stream\lib\_stream_writable.js:241:11)
    at write (C:\Users\me\Downloads\x\node_modules\vinyl-fs\node_modules\readable-stream\lib\_stream_readable.js:623:24)
    at flow (C:\Users\me\Downloads\x\node_modules\vinyl-fs\node_modules\readable-stream\lib\_stream_readable.js:632:7)
    at DestroyableTransform.pipeOnReadable (C:\Users\me\Downloads\x\node_modules\vinyl-fs\node_modules\readable-stream\lib\_stream_readable.js:664:5)
    at emitNone (events.js:106:13)
    at DestroyableTransform.emit (events.js:208:7)
    at emitReadable_ (C:\Users\me\Downloads\x\node_modules\vinyl-fs\node_modules\readable-stream\lib\_stream_readable.js:448:10)
    at emitReadable (C:\Users\me\Downloads\x\node_modules\vinyl-fs\node_modules\readable-stream\lib\_stream_readable.js:444:5)
    at readableAddChunk (C:\Users\me\Downloads\x\node_modules\vinyl-fs\node_modules\readable-stream\lib\_stream_readable.js:187:9)
    at DestroyableTransform.Readable.push (C:\Users\me\Downloads\x\node_modules\vinyl-fs\node_modules\readable-stream\lib\_stream_readable.js:149:10)
    at DestroyableTransform.Transform.push (C:\Users\me\Downloads\x\node_modules\vinyl-fs\node_modules\readable-stream\lib\_stream_transform.js:145:32)
    at afterTransform (C:\Users\me\Downloads\x\node_modules\vinyl-fs\node_modules\readable-stream\lib\_stream_transform.js:101:12)
    at TransformState.afterTransform (C:\Users\me\Downloads\x\node_modules\vinyl-fs\node_modules\readable-stream\lib\_stream_transform.js:79:12)
    at DestroyableTransform.noop [as _transform] (C:\Users\me\Downloads\x\node_modules\vinyl-fs\node_modules\through2\through2.js:26:3)
    at DestroyableTransform.Transform._read (C:\Users\me\Downloads\x\node_modules\vinyl-fs\node_modules\readable-stream\lib\_stream_transform.js:184:10)
    at DestroyableTransform.Transform._write (C:\Users\me\Downloads\x\node_modules\vinyl-fs\node_modules\readable-stream\lib\_stream_transform.js:172:12)
    at doWrite (C:\Users\me\Downloads\x\node_modules\vinyl-fs\node_modules\readable-stream\lib\_stream_writable.js:237:10)
    at writeOrBuffer (C:\Users\me\Downloads\x\node_modules\vinyl-fs\node_modules\readable-stream\lib\_stream_writable.js:227:5)
    at DestroyableTransform.Writable.write (C:\Users\me\Downloads\x\node_modules\vinyl-fs\node_modules\readable-stream\lib\_stream_writable.js:194:11)
[14:34:54] 'push' errored after 2.05 s
[14:34:54] StatusCodeError in plugin "gulp-spsave"
Message:
    401 - undefined
Details:
    statusCode: 401
    error: undefined
    options: [object Object]
    response: [object Object]

Stack:
StatusCodeError: 401 - undefined
    at new StatusCodeError (C:\Users\me\Downloads\x\node_modules\request-promise-core\lib\errors.js:32:15)
    at Request.plumbing.callback (C:\Users\me\Downloads\x\node_modules\request-promise-core\lib\plumbing.js:104:33)
    at Request.RP$callback [as _callback] (C:\Users\me\Downloads\x\node_modules\request-promise-core\lib\plumbing.js:46:31)
    at Request.self.callback (C:\Users\me\Downloads\x\node_modules\request\request.js:185:22)
    at emitTwo (events.js:126:13)
    at Request.emit (events.js:214:7)
    at Request.<anonymous> (C:\Users\me\Downloads\x\node_modules\request\request.js:1161:10)
    at emitOne (events.js:116:13)
    at Request.emit (events.js:211:7)
    at IncomingMessage.<anonymous> (C:\Users\me\Downloads\x\node_modules\request\request.js:1083:12)
    at Object.onceWrapper (events.js:313:30)
    at emitNone (events.js:111:20)
    at IncomingMessage.emit (events.js:208:7)
    at endReadableNT (_stream_readable.js:1064:12)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)
From previous event:
    at coreRequest (C:\Users\me\Downloads\x\node_modules\sp-request\lib\src\core\SPRequest.js:22:16)
    at spRequestFunc (C:\Users\me\Downloads\x\node_modules\sp-request\lib\src\core\SPRequest.js:69:20)
    at Function.spRequestFunc.(anonymous function) [as post] (C:\Users\me\Downloads\x\node_modules\sp-request\lib\src\core\SPRequest.js:109:24)
    at C:\Users\me\Downloads\x\node_modules\sp-request\lib\src\core\SPRequest.js:87:27
From previous event:
    at Function.spRequestFunc.requestDigest (C:\Users\me\Downloads\x\node_modules\sp-request\lib\src\core\SPRequest.js:79:16)
    at C:\Users\me\Downloads\x\node_modules\spsave\lib\src\core\FileSaver.js:54:36
    at runCallback (timers.js:810:20)
    at tryOnImmediate (timers.js:768:5)
    at processImmediate [as _immediateCallback] (timers.js:745:5)
From previous event:
    at FileSaver.saveFile (C:\Users\me\Downloads\x\node_modules\spsave\lib\src\core\FileSaver.js:53:14)
    at FileSaver.save (C:\Users\me\Downloads\x\node_modules\spsave\lib\src\core\FileSaver.js:38:18)
    at saveSingleFile (C:\Users\me\Downloads\x\node_modules\spsave\lib\src\core\SPSave.js:80:76)
    at C:\Users\me\Downloads\x\node_modules\spsave\lib\src\core\SPSave.js:41:13
From previous event:
    at spsave (C:\Users\me\Downloads\x\node_modules\spsave\lib\src\core\SPSave.js:13:12)
    at DestroyableTransform.uploadFile [as _transform] (C:\Users\me\Downloads\x\node_modules\gulp-spsave\index.js:42:7)
    at DestroyableTransform.Transform._read (C:\Users\me\Downloads\x\node_modules\gulp-spsave\node_modules\readable-stream\lib\_stream_transform.js:159:10)
    at DestroyableTransform.Transform._write (C:\Users\me\Downloads\x\node_modules\gulp-spsave\node_modules\readable-stream\lib\_stream_transform.js:147:83)
    at doWrite (C:\Users\me\Downloads\x\node_modules\gulp-spsave\node_modules\readable-stream\lib\_stream_writable.js:313:64)
    at writeOrBuffer (C:\Users\me\Downloads\x\node_modules\gulp-spsave\node_modules\readable-stream\lib\_stream_writable.js:302:5)
    at DestroyableTransform.Writable.write (C:\Users\me\Downloads\x\node_modules\gulp-spsave\node_modules\readable-stream\lib\_stream_writable.js:241:11)
    at write (C:\Users\me\Downloads\x\node_modules\vinyl-fs\node_modules\readable-stream\lib\_stream_readable.js:623:24)
    at flow (C:\Users\me\Downloads\x\node_modules\vinyl-fs\node_modules\readable-stream\lib\_stream_readable.js:632:7)
    at DestroyableTransform.pipeOnReadable (C:\Users\me\Downloads\x\node_modules\vinyl-fs\node_modules\readable-stream\lib\_stream_readable.js:664:5)
    at emitNone (events.js:106:13)
    at DestroyableTransform.emit (events.js:208:7)
    at emitReadable_ (C:\Users\me\Downloads\x\node_modules\vinyl-fs\node_modules\readable-stream\lib\_stream_readable.js:448:10)
    at emitReadable (C:\Users\me\Downloads\x\node_modules\vinyl-fs\node_modules\readable-stream\lib\_stream_readable.js:444:5)
    at readableAddChunk (C:\Users\me\Downloads\x\node_modules\vinyl-fs\node_modules\readable-stream\lib\_stream_readable.js:187:9)
    at DestroyableTransform.Readable.push (C:\Users\me\Downloads\x\node_modules\vinyl-fs\node_modules\readable-stream\lib\_stream_readable.js:149:10)
    at DestroyableTransform.Transform.push (C:\Users\me\Downloads\x\node_modules\vinyl-fs\node_modules\readable-stream\lib\_stream_transform.js:145:32)
    at afterTransform (C:\Users\me\Downloads\x\node_modules\vinyl-fs\node_modules\readable-stream\lib\_stream_transform.js:101:12)
    at TransformState.afterTransform (C:\Users\me\Downloads\x\node_modules\vinyl-fs\node_modules\readable-stream\lib\_stream_transform.js:79:12)
    at DestroyableTransform.noop [as _transform] (C:\Users\me\Downloads\x\node_modules\vinyl-fs\node_modules\through2\through2.js:26:3)
    at DestroyableTransform.Transform._read (C:\Users\me\Downloads\x\node_modules\vinyl-fs\node_modules\readable-stream\lib\_stream_transform.js:184:10)
    at DestroyableTransform.Transform._write (C:\Users\me\Downloads\x\node_modules\vinyl-fs\node_modules\readable-stream\lib\_stream_transform.js:172:12)
    at doWrite (C:\Users\me\Downloads\x\node_modules\vinyl-fs\node_modules\readable-stream\lib\_stream_writable.js:237:10)
    at writeOrBuffer (C:\Users\me\Downloads\x\node_modules\vinyl-fs\node_modules\readable-stream\lib\_stream_writable.js:227:5)
    at DestroyableTransform.Writable.write (C:\Users\me\Downloads\x\node_modules\vinyl-fs\node_modules\readable-stream\lib\_stream_writable.js:194:11)

Error when uploading to HTTPS SharePoint server

I try to upload a document to a SharePoint site on HTTPS protocol using spsave, but I get the following
error: 'Cannot read property 'match' of undefined' - it occurs during the NTLM authentication process with the server (inside the node module 'httpntlm').
I sent the following arguments to spsave:
coreOptions contains 'siteUrl' of the form : 'https://SERVER_NAME/SP_SITE_NAME'
creds contains my username and password,
fileOptions contains 'folder' of the form 'LIBRARY_NAME/FOLDER_NAME', fileName, and fileContent.

When trying to upload a file to a different SharePoint site- that uses HTTP with the same arguments - it works well, and file is uploaded.

Aspx pages

I tried to use this to move and ASPX page and I got an access denied error, So I tried changing it to an HTML page and that worked fine. Any ideas?

401 - undefined error

I get the following error when I try to use spsave

[14:32:20] spsave: Error occured:
[14:32:20] spsave: 401 - undefined

[14:32:20] spsave: Stack trace:

[14:32:20] spsave: StatusCodeError: 401 - undefined
at new StatusCodeError (C:\Users\kk\Downloads\KD\node_modules\request-promise-core\lib\errors.js:32:15)
at Request.plumbing.callback (C:\Users\kk\Downloads\KD\node_modules\request-promise-core\lib\plumbing.js:104:33)
at Request.RP$callback [as _callback] (C:\Users\kk\Downloads\KD\node_modules\request-promise-core\lib\plumbing.js:46:31)
at Request.self.callback (C:\Users\kk\Downloads\KD\node_modules\request\request.js:186:22)
at emitTwo (events.js:126:13)
at Request.emit (events.js:214:7)
at Request. (C:\Users\kk\Downloads\KD\node_modules\request\request.js:1163:10)
at emitOne (events.js:116:13)
at Request.emit (events.js:211:7)
at IncomingMessage. (C:\Users\kk\Downloads\KD\node_modules\request\request.js:1085:12)
at Object.onceWrapper (events.js:313:30)
at emitNone (events.js:111:20)
at IncomingMessage.emit (events.js:208:7)
at endReadableNT (_stream_readable.js:1055:12)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)

My gulpfile

var gulp = require("gulp"); var spsave = require("gulp-spsave"); var coreOptions = { siteUrl: "xxxxxx", folder: "Style Library/js/", notification: true }; var creds = { username:'[email protected]', password:'xxx' }; gulp.task("upload", function () { return gulp.src("./assets/*.js").pipe(spsave(coreOptions,creds)); });

I have also tried using ondemand authentication with the same credentials and I get this error message

[14:46:08] spsave: Error occured:
[14:46:08] spsave: 403 - {"error":{"code":"-2147024891, System.UnauthorizedAccessException","message":{"lang":"en-US","value":"Access denied. You do not have permission to perform this action or access this resource."}}}

[14:46:08] spsave: Stack trace:

[14:46:08] spsave: StatusCodeError: 403 - {"error":{"code":"-2147024891, System.UnauthorizedAccessException","message":{"lang":"en-US","value":"Access denied. You do not have permission to perform this action or access this resource."}}}
at new StatusCodeError (C:\Users\kk\Downloads\KD\node_modules\request-promise-core\lib\errors.js:32:15)
at Request.plumbing.callback (C:\Users\kk\Downloads\KD\node_modules\request-promise-core\lib\plumbing.js:104:33)
at Request.RP$callback [as _callback] (C:\Users\kk\Downloads\KD\node_modules\request-promise-core\lib\plumbing.js:46:31)
at Request.self.callback (C:\Users\kk\Downloads\KD\node_modules\request\request.js:186:22)
at emitTwo (events.js:126:13)
at Request.emit (events.js:214:7)
at Request. (C:\Users\kk\Downloads\KD\node_modules\request\request.js:1163:10)
at emitOne (events.js:116:13)
at Request.emit (events.js:211:7)
at IncomingMessage. (C:\Users\kk\Downloads\KD\node_modules\request\request.js:1085:12)
at Object.onceWrapper (events.js:313:30)
at emitNone (events.js:111:20)
at IncomingMessage.emit (events.js:208:7)
at endReadableNT (_stream_readable.js:1055:12)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)

Promise is neither resolved or rejected when glob pattern matches 0 files

Hello @s-KaiNet !

I'm building glob support into SPGo, and I found that the returned promise object never fulfils when I provide a glob pattern that matches 0 files. I tried using finally() as a workaround, but no luck.

Example Fix:
to function spsave in file SPSave.js, add the following conditional to the end of the if/else block:
else{ reject({title: "0 Files Matched",message:"Glob pattern matched 0 files"} }

Let me know if you want me to author a PR, and whether you'd rather me author it directly against the repo, or via fork.

Thanks,
Chris

office365 sync file failed, sharepoint 2013 is ok. The error message as following:

[14:03:56] spsave: Error occured:
[14:03:56] spsave: Invalid STS request.

[14:03:56] spsave: Stack trace:

[14:03:56] spsave: Error: Invalid STS request.

 at C:\zhou__project_\nodejs\days\process\node_modules\spsave\node_modules\sp-request\node_module
s\node-spoauth\sharepoint.js:196:13
    at C:\zhou__project_\nodejs\days\process\node_modules\spsave\node_modules\sp-request\node_module
s\node-spoauth\sharepoint.js:119:21
    at Parser.<anonymous> (C:\zhou__project_\nodejs\days\process\node_modules\spsave\node_modules\sp
-request\node_modules\node-spoauth\sharepoint.js:28:21)
    at emitOne (events.js:77:13)
    at Parser.emit (events.js:169:7)
    at Object.onclosetag (C:\zhou__project_\nodejs\days\process\node_modules\spsave\node_modules\sp-
request\node_modules\node-spoauth\node_modules\xml2js\lib\xml2js.js:447:26)
    at emit (C:\zhou__project_\nodejs\days\process\node_modules\spsave\node_modules\sp-request\node_
modules\node-spoauth\node_modules\xml2js\node_modules\sax\lib\sax.js:640:35)
    at emitNode (C:\zhou__project_\nodejs\days\process\node_modules\spsave\node_modules\sp-request\n
ode_modules\node-spoauth\node_modules\xml2js\node_modules\sax\lib\sax.js:645:5)
    at closeTag (C:\zhou__project_\nodejs\days\process\node_modules\spsave\node_modules\sp-request\n
ode_modules\node-spoauth\node_modules\xml2js\node_modules\sax\lib\sax.js:905:7)
    at Object.write (C:\zhou__project_\nodejs\days\process\node_modules\spsave\node_modules\sp-reque
st\node_modules\node-spoauth\node_modules\xml2js\node_modules\sax\lib\sax.js:1449:13)
    at Parser.exports.Parser.Parser.parseString (C:\zhou__project_\nodejs\days\process\node_modules\
spsave\node_modules\sp-request\node_modules\node-spoauth\node_modules\xml2js\lib\xml2js.js:508:31)
    at Parser.parseString (C:\zhou__project_\nodejs\days\process\node_modules\spsave\node_modules\sp
-request\node_modules\node-spoauth\node_modules\xml2js\lib\xml2js.js:7:59)
    at parseXml (C:\zhou__project_\nodejs\days\process\node_modules\spsave\node_modules\sp-request\n
ode_modules\node-spoauth\sharepoint.js:31:12)
    at IncomingMessage.<anonymous> (C:\zhou__project_\nodejs\days\process\node_modules\spsave\node_m
odules\sp-request\node_modules\node-spoauth\sharepoint.js:112:13)
From previous event:
    at C:\zhou__project_\nodejs\days\process\node_modules\spsave\node_modules\sp-request\lib\src\cor
e\auth\OnlineResolver.js:24:13
From previous event:
    at OnlineResolver.applyAuthHeaders (C:\zhou__project_\nodejs\days\process\node_modules\spsave\no
de_modules\sp-request\lib\src\core\auth\OnlineResolver.js:13:16)
    at C:\zhou__project_\nodejs\days\process\node_modules\spsave\node_modules\sp-request\lib\src\cor
e\SPRequest.js:28:18
From previous event:
    at coreRequest (C:\zhou__project_\nodejs\days\process\node_modules\spsave\node_modules\sp-reques
t\lib\src\core\SPRequest.js:12:16)
    at spRequestFunc (C:\zhou__project_\nodejs\days\process\node_modules\spsave\node_modules\sp-requ
est\lib\src\core\SPRequest.js:52:20)
    at Function.spRequestFunc.(anonymous function) [as post] (C:\zhou__project_\nodejs\days\process\
node_modules\spsave\node_modules\sp-request\lib\src\core\SPRequest.js:92:24)
    at C:\zhou__project_\nodejs\days\process\node_modules\spsave\node_modules\sp-request\lib\src\cor
e\SPRequest.js:70:27
From previous event:
    at Function.spRequestFunc.requestDigest (C:\zhou__project_\nodejs\days\process\node_modules\spsa
ve\node_modules\sp-request\lib\src\core\SPRequest.js:62:16)
    at C:\zhou__project_\nodejs\days\process\node_modules\spsave\lib\src\core\FileSaver.js:53:36
    at processImmediate [as _immediateCallback] (timers.js:383:17)
From previous event:
    at FileSaver.saveFile (C:\zhou__project_\nodejs\days\process\node_modules\spsave\lib\src\core\Fi
leSaver.js:52:14)
    at FileSaver.save (C:\zhou__project_\nodejs\days\process\node_modules\spsave\lib\src\core\FileSa
ver.js:37:18)
    at saveSingleFile (C:\zhou__project_\nodejs\days\process\node_modules\spsave\lib\src\core\SPSave
.js:69:47)
    at saveFileArray (C:\zhou__project_\nodejs\days\process\node_modules\spsave\lib\src\core\SPSave.
js:54:9)
    at C:\zhou__project_\nodejs\days\process\node_modules\spsave\lib\src\core\SPSave.js:25:13
From previous event:
    at spsave (C:\zhou__project_\nodejs\days\process\node_modules\spsave\lib\src\core\SPSave.js:12:1
2)
    at save (C:\zhou__project_\nodejs\days\process\gulpfile.js:16:3)
    at Gulp.<anonymous> (C:\zhou__project_\nodejs\days\process\gulpfile.js:30:2)
    at module.exports (C:\zhou__project_\nodejs\days\process\node_modules\gulp\node_modules\orchestr
ator\lib\runTask.js:34:7)
    at Gulp.Orchestrator._runTask (C:\zhou__project_\nodejs\days\process\node_modules\gulp\node_modu
les\orchestrator\index.js:273:3)
    at Gulp.Orchestrator._runStep (C:\zhou__project_\nodejs\days\process\node_modules\gulp\node_modu
les\orchestrator\index.js:214:10)
    at Gulp.Orchestrator.start (C:\zhou__project_\nodejs\days\process\node_modules\gulp\node_modules
\orchestrator\index.js:134:8)
    at C:\Users\zhouzh\AppData\Roaming\npm\node_modules\gulp\bin\gulp.js:129:20
    at doNTCallback0 (node.js:419:9)
    at process._tickCallback (node.js:348:13)
    at Function.Module.runMain (module.js:469:11)
    at startup (node.js:136:18)
    at node.js:963:3
{ [Error: Invalid STS request.
]
  cause:
   [Error: Invalid STS request.
   ],
  isOperational: true }

404 NOT FOUND

Hi there

I'm not sure whether this is a bug or just an inability of me. Issuing following cURL request successfully uploads the filename.txt file to the specified folder.

curl -v --ntlm --user [username]@[domain].ch:[password] --upload-file fielname.txt
https://sharepoint.[domain].ch/path/to/folder/filename.txt

However, if I use spsave with the following settings:

var sp;

sp = require('spsave');

sp.spsave({
        siteUrl: 'https://sharepoint.[domain].ch',
        username: '[username]@[domain].ch',
        password: '[password]',
        folder: "path/to/folder",
        fileName: 'filename.txt',
        fileContent: 'test',
        checkin: true,
        checkinType: 1
    })
    .then(function() {
        console.log('saved');
    })
    .catch(function(err) {
        console.log(err.message);
    }); 

then I receive the following error:

[08:14:13] spsave: Error occured:
[08:14:13] spsave: 404 - "404 NOT FOUND"

[08:14:13] spsave: Stack trace:

[08:14:13] spsave: StatusCodeError: 404 - "404 NOT FOUND"
    at new StatusCodeError (/opt/turntable/node_modules/request-promise/lib/errors.js:32:15)
    at Request.RP$callback [as _callback] (/opt/turntable/node_modules/request-promise/lib/rp.js:77:29)
    at Request.self.callback (/opt/turntable/node_modules/request/request.js:200:22)
    at emitTwo (events.js:87:13)
    at Request.emit (events.js:172:7)
    at Request.<anonymous> (/opt/turntable/node_modules/request/request.js:1041:10)
    at emitOne (events.js:82:20)
    at Request.emit (events.js:169:7)
    at IncomingMessage.<anonymous> (/opt/turntable/node_modules/request/request.js:968:12)
    at emitNone (events.js:72:20)
    at IncomingMessage.emit (events.js:166:7)
    at endReadableNT (_stream_readable.js:913:12)
    at nextTickCallbackWith2Args (node.js:442:9)
    at process._tickCallback (node.js:356:17)
From previous event:
    at FileSaver.checkoutFile (/opt/turntable/node_modules/spsave/lib/src/core/FileSaver.js:166:23)
    at FileSaver.saveFile (/opt/turntable/node_modules/spsave/lib/src/core/FileSaver.js:48:35)
    at FileSaver.save (/opt/turntable/node_modules/spsave/lib/src/core/FileSaver.js:35:18)
    at saveSingleFile (/opt/turntable/node_modules/spsave/lib/src/core/SPSave.js:71:47)
    at /opt/turntable/node_modules/spsave/lib/src/core/SPSave.js:37:13
From previous event:
    at Object.spsave (/opt/turntable/node_modules/spsave/lib/src/core/SPSave.js:13:12)
    at Object.<anonymous> (/path/to/script/sharepoint.js:5:4)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Function.Module.runMain (module.js:441:10)
    at startup (node.js:139:18)
    at node.js:968:3

The error is thrown while trying to get the GetFileByServerRelativeUrl via GET request.
https://sharepoint.[domain].ch/_api/web/GetFileByServerRelativeUrl(@FileUrl)?@FileUrl=\'[path/to/folder/filename.txt\'

Why does spsave wants to get the file by server relative url? I want to upload and not to download the file.

Best,
Michael

Add the ability to add metadata to a file

It would be great if you can set metadata to a file once it is uploaded. Some script files require metadata to be set in order to work, like for example display templates.

How to clear credential cache?

@s-KaiNet, this might be a silly question:

If I pass 'null' (no authentication) as credentialOptions, the url, username, domain, password, ... are asked in the console which is awesome. Afterward, according to the docs, the credentials are saved 'in a user folder'.

Now, I have mistyped my password, the wrong credentials are stored and spsave keeps using these wrong credentials. How can I clear the stored credentials?

I searched in the docs of node-sp-auth-config and the default path seems to be "./config/private.json". However, I don't find a private.json on my Windows system. Do you know where I can find this file? I guess that by removing this file, I will be able to re-enter the correct credentials...

no authentication - do not provide any authentication data at all, like spauth.getAuth(url).then(...). In that case node-sp-auth will ask you for the site url and credentials. You will have to select any of the credential options listed above. Credentials will be stored in a user folder in an encrypted manner.

upload file to SharePoint Online failed

I try to upload file to SharePoint Online, but get the following error message:

[13:39:04] Using gulpfile C:\zhou__project_\tss\gulpfile.js
[13:39:04] Starting 'level1'...
[13:39:04] Finished 'level1' after 21 ms
[13:39:04] Starting 'default'...
[13:39:04] Finished 'default' after 63 μs
[13:39:05] spsave: Error occured:
[13:39:05] spsave: Error: socket hang up

[13:39:05] spsave: Stack trace:

[13:39:05] spsave: RequestError: Error: socket hang up
    at new RequestError (C:\zhou__project_\tss\node_modules\request-promise-core
\lib\errors.js:14:15)
    at Request.plumbing.callback (C:\zhou__project_\tss\node_modules\request-pro
mise-core\lib\plumbing.js:87:29)
    at Request.RP$callback [as _callback] (C:\zhou__project_\tss\node_modules\re
quest-promise-core\lib\plumbing.js:46:31)
    at self.callback (C:\zhou__project_\tss\node_modules\request\request.js:186:
22)
    at emitOne (events.js:96:13)
    at Request.emit (events.js:188:7)
    at Request.onRequestError (C:\zhou__project_\tss\node_modules\request\reques
t.js:845:8)
    at emitOne (events.js:96:13)
    at ClientRequest.emit (events.js:188:7)
    at TLSSocket.socketOnEnd (_http_client.js:344:9)
    at emitNone (events.js:91:20)
    at TLSSocket.emit (events.js:185:7)
    at endReadableNT (_stream_readable.js:973:12)
    at _combinedTickCallback (internal/process/next_tick.js:74:11)
From previous event:
    at coreRequest (C:\zhou__project_\tss\node_modules\sp-request\lib\src\core\S
PRequest.js:15:16)
    at spRequestFunc (C:\zhou__project_\tss\node_modules\sp-request\lib\src\core
\SPRequest.js:56:20)
    at Function.spRequestFunc.(anonymous function) [as get] (C:\zhou__project_\t
ss\node_modules\sp-request\lib\src\core\SPRequest.js:96:24)
    at FileSaver.getFileByUrl (C:\zhou__project_\tss\node_modules\spsave\lib\src
\core\FileSaver.js:210:31)
    at C:\zhou__project_\tss\node_modules\spsave\lib\src\core\FileSaver.js:175:1
9
From previous event:
    at FileSaver.checkoutFile (C:\zhou__project_\tss\node_modules\spsave\lib\src
\core\FileSaver.js:170:23)
    at FileSaver.saveFile (C:\zhou__project_\tss\node_modules\spsave\lib\src\cor
e\FileSaver.js:50:35)
    at FileSaver.save (C:\zhou__project_\tss\node_modules\spsave\lib\src\core\Fi
leSaver.js:37:18)
    at saveSingleFile (C:\zhou__project_\tss\node_modules\spsave\lib\src\core\SP
Save.js:74:76)
    at C:\zhou__project_\tss\node_modules\spsave\lib\src\core\SPSave.js:40:13
From previous event:
    at spsave (C:\zhou__project_\tss\node_modules\spsave\lib\src\core\SPSave.js:
12:12)
    at Gulp.<anonymous> (C:\zhou__project_\tss\gulpfile.js:31:5)
    at module.exports (C:\zhou__project_\tss\node_modules\orchestrator\lib\runTa
sk.js:34:7)
    at Gulp.Orchestrator._runTask (C:\zhou__project_\tss\node_modules\orchestrat
or\index.js:273:3)
    at Gulp.Orchestrator._runStep (C:\zhou__project_\tss\node_modules\orchestrat
or\index.js:214:10)
    at Gulp.Orchestrator.start (C:\zhou__project_\tss\node_modules\orchestrator\
index.js:134:8)
    at C:\Users\zhouzh\AppData\Roaming\npm\node_modules\gulp-cli\lib\versioned\^
3.7.0\index.js:46:20
    at _combinedTickCallback (internal/process/next_tick.js:67:7)
    at process._tickCallback (internal/process/next_tick.js:98:9)
    at Module.runMain (module.js:577:11)
    at run (bootstrap_node.js:352:7)
    at startup (bootstrap_node.js:144:9)
    at bootstrap_node.js:467:3
{"name":"RequestError","message":"Error: socket hang up","cause":{"code":"ECONNR
ESET"},"error":{"code":"ECONNRESET"},"options":{"simple":false,"strictSSL":false
,"json":true,"form":{"login":"[email protected]"},"uri":"https://login.microso
ftonline.com/GetUserRealm.srf","method":"POST","resolveWithFullResponse":false,"
transform2xxOnly":false}}

My gulp task:

const coreOptions = {
    siteUrl: env.staging,
    notification: true,
    checkin: true,
    checkinType: 1
}

const creds = {
    username: '[email protected]' , 
    password: '**********'
}

const fileOptions = {
    folder: 'SiteAssets',
    fileName: 'test.txt',
    fileContent: '0'
}

gulp.task('default', function() {
    spsave(coreOptions, creds, fileOptions)
    .then(function() {
        console.log('uploaded!');
    }).catch(function(err) {
        console.log(JSON.stringify(err));
    });
})

Could you help me?

Error uploading files when no checkin set

When I try to omit the optional checkin boolean and upload a new version of files that already exist, I get a "must be checked out" error.

Example: I have a folder with a test.html file in it. The folder requires check in and check out. I want to upload a new version of this test.html file but I don't want to check it in after uploading.

I can omit the checkin boolean and upload files if the files are new or if the files are already checked out, but not if they exist already and aren't checked out.

With the checkin option being optional and the options to check in major or minor versions, I thought that I would also be able to replace an existing file and not check it in.

Am I doing this incorrectly?

    var spsave = require("spsave").spsave;
    spsave({
        siteUrl: 'my url',
    }, null, {
        glob: 'dist/css/**',
        folder: 'Style%20Library/branding/',
        base: 'dist'
    })
    .then(function(){
        console.log('saved');
    })
    .catch(function(err){
        console.log(err);
    });

Dev-only install causes packaging errors from SPSave

Hello @s-KaiNet

Since SPGo 1.2.0, I've been using SPSave 3.1.2. It appears that there has been a change in how packages and types are linked in this version and it is now recommended to be installed as a dev dependency (npm install spsave --save-dev). Unfortunately, for SPGo that prevents spsave from being included in the production package that is deployed to the VSCode marketplace. If i try to install the package as a prod depenency (either via npm install or with the --save-prod flag) packaging will fail with a number of npm errors.

Is there a hard requirement to install spsave as a dev dependency, is there a way to install spsave without extraneous errors, or is this a PEBKAC error on my part and you have guidance you can provide on how to fix the errors below?

**NPM Errors when installed or listed as a production dependency **

npm ERR! extraneous: @types/[email protected] C:\Users\chris\Projects\spgo\node_modules\spsave\node_modules\@types\mocha
npm ERR! extraneous: @types/[email protected] C:\Users\chris\Projects\spgo\node_modules\spsave\node_modules\@types\mockery
npm ERR! extraneous: @types/[email protected] C:\Users\chris\Projects\spgo\node_modules\spsave\node_modules\@types\sinon
npm ERR! extraneous: [email protected] C:\Users\chris\Projects\spgo\node_modules\spsave\node_modules\chai
npm ERR! extraneous: [email protected] C:\Users\chris\Projects\spgo\node_modules\spsave\node_modules\console.table
npm ERR! extraneous: [email protected] C:\Users\chris\Projects\spgo\node_modules\spsave\node_modules\coveralls
npm ERR! extraneous: [email protected] C:\Users\chris\Projects\spgo\node_modules\spsave\node_modules\del
npm ERR! extraneous: [email protected] C:\Users\chris\Projects\spgo\node_modules\spsave\node_modules\gulp
npm ERR! extraneous: [email protected] C:\Users\chris\Projects\spgo\node_modules\spsave\node_modules\gulp-debug
npm ERR! extraneous: [email protected] C:\Users\chris\Projects\spgo\node_modules\spsave\node_modules\gulp-istanbul
npm ERR! extraneous: [email protected] C:\Users\chris\Projects\spgo\node_modules\spsave\node_modules\gulp-load-plugins
npm ERR! extraneous: [email protected] C:\Users\chris\Projects\spgo\node_modules\spsave\node_modules\gulp-mocha
npm ERR! extraneous: [email protected] C:\Users\chris\Projects\spgo\node_modules\spsave\node_modules\gulp-plumber
npm ERR! extraneous: [email protected] C:\Users\chris\Projects\spgo\node_modules\spsave\node_modules\gulp-sourcemaps
npm ERR! extraneous: [email protected] C:\Users\chris\Projects\spgo\node_modules\spsave\node_modules\gulp-tslint
npm ERR! extraneous: [email protected] C:\Users\chris\Projects\spgo\node_modules\spsave\node_modules\gulp-typescript
npm ERR! extraneous: [email protected] C:\Users\chris\Projects\spgo\node_modules\spsave\node_modules\map-stream
npm ERR! extraneous: [email protected] C:\Users\chris\Projects\spgo\node_modules\spsave\node_modules\mocha-junit-reporter
npm ERR! extraneous: [email protected] C:\Users\chris\Projects\spgo\node_modules\spsave\node_modules\mockery
npm ERR! extraneous: [email protected] C:\Users\chris\Projects\spgo\node_modules\spsave\node_modules\remap-istanbul
npm ERR! extraneous: [email protected] C:\Users\chris\Projects\spgo\node_modules\spsave\node_modules\run-sequence
npm ERR! extraneous: [email protected] C:\Users\chris\Projects\spgo\node_modules\spsave\node_modules\sinon
npm ERR! extraneous: [email protected] C:\Users\chris\Projects\spgo\node_modules\spsave\node_modules\tslint
npm ERR! extraneous: [email protected] C:\Users\chris\Projects\spgo\node_modules\spsave\node_modules\typings
npm ERR! extraneous: [email protected] C:\Users\chris\Projects\spgo\node_modules\spsave\node_modules\yargs```

Thanks, again, for all of your help to date!

-Chris

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.