1.2.5 • Published 2 months ago

nextcloud-chunk-file-upload v1.2.5

Weekly downloads
178
License
MIT
Repository
github
Last release
2 months ago

Nextcloud Chunk File Upload

Upload files to Nextcloud using chunks

Nextcloud offers a chunked upload library, which makes your life a lot easier, if you want to upload large files to your Nextcloud instance over a bad network.

Use this library if you want to build some sort of upload client in node.js and do that with the joy of Promises 🙌.

Installation

This package is published on NPM so you can simply type:

npm install --save nextcloud-chunk-file-upload

or

yarn add nextcloud-chunk-file-upload

Usage

Upload

The core part of this library is a class called Upload, which takes care of server parameters, like the server's address and your credentials. If you want to start an upload, call uploadFile. The return value of this method is Promise, indicating the success or failure of the upload process.

Methods

constructor(url, userspace, username, password)

NameRequiredTypeDefaultDescription
urlyesstringURL to WebDav API
userspaceyesstringUser key on the filesystem on the server (usually the same as username)
usernameyesstringCredentials: Username
passwordyesstringCredentials: Password

uploadFile(localPath, remotePath, chunkSize, retryChunks, createDirsRecursively): Promise<Event>

NameRequiredTypeDefaultDescription
localPathyesstringPath of file on local machine
remotePathyesstringPath the file should be placed on the server
chunkSizenonumber2MBThe max size of chunks in bytes
retryChunksnonumber5Number of retry attempts for uploading a chunk
createDirsRecursivelynobooleanfalseCreate sub directories of upload path recursively

Event

Upload.uploadFile returns a promise containing an event object. This object holds information about the result of the upload.

Member variables

NameTypeDescription
filenamestringLocal file path
chunkNonumberSequence number of the current chunk
messagestringEvent reason
completebooleanWhether the upload was successful
httpErrorCodenumberHTTP response code, if upload failed
httpErrorMessagestringHTTP response body, if upload failed

Methods

toString(): string

Returns a string containg the event data

Example

A simple upload code could look like this:

const Upload = require('nextcloud-chunk-file-upload');

const upload = new Upload('https://example.com/remote.php/dav', 'myuser', 'myspace', 'secret');

upload.uploadFile('/path/to/localfile.jpg', '/path/to/remotefile.jpg')
  .then(event => {
    console.log('Success!');
    console.log(event.toString());
  })
  .catch(event => {
    console.error('Sth. went wrong')
    console.error(event.toString());
  });

License

This project is licensed under the MIT license. See LICENSE file.

1.2.5

2 months ago

1.2.4

3 months ago

1.2.3

6 months ago

1.2.2

7 months ago

1.2.1

7 months ago

1.2.0

10 months ago

1.1.1

1 year ago

1.1.0

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

4 years ago

1.0.0

4 years ago