Skip to content

A strophe.js plugin for file upload using HTTP File Upload (XEP-0363)

License

Notifications You must be signed in to change notification settings

AnishLushte07/strophejs-plugin-http-file-upload

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 [email protected] 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.

About

A strophe.js plugin for file upload using HTTP File Upload (XEP-0363)

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published