Skip to content

Latest commit

 

History

History
78 lines (53 loc) · 2.13 KB

README.markdown

File metadata and controls

78 lines (53 loc) · 2.13 KB

Strophe http-file-upload

Plugin for strophe.js to provide HTTP File Upload (XEP-0363).

Install

This is a Node.js module available through the npm registry. Installation is done using the npm install command:

$ npm install strophejs-plugin-http-file-upload

Initialization

connection.httpUpload.init(connection);

Usage

Generate GET and PUT URL for file

connection.httpUpload.getUrls(file, success_cb, error_cb)

file is the File object which you want to upload.

success_cb is a function to be called on success with urls:

error_cb is a function to be called in case of error.

Function will return object with put and get url. You can use put url to upload file using http.

Example

Generate get and put url for file:

var file = {
    name: 'filename.png',
    size: 4512, // in bytes
    type: 'image/png',
    ... // other data
}

function uploadFile(file, url) {
    var xhr = new XMLHttpRequest();

    xhr.onreadystatechange = function() {
        if (xhr.readyState === 4) {
            console.log('File Uploaded Successfully.');
        }
    };

    xhr.open("PUT", url, true);
    xhr.setRequestHeader('Content-Type', 'text/plain');
    xhr.send(file);
}

connection.httpUpload.getUrls(
    file,
    function(data) {
        console.log("PUT URL: ", data.put, "GET URL: ", data.get);
        uploadFile(file, data.put);
        return true;
    },
    function(err) {
        console.error(err);
    }
);

License

strophejs-plugin-http-file-upload is copyright (c) 2019-present Anish Lushte lushteanish@gmail.com and the contributors to Node-Minio.

strophejs-plugin-http-file-upload is free software, licensed under the MIT License. See the LICENSE file for more details.