Code Monkey home page Code Monkey logo

progressuploader's Introduction

ProgressUploader

Multipart Upload of text file. Tracks upload progress

This lib will work as is but it's more of an example of how this can be achieved so that you can implement your own code. For example you might want to upload non-text (binary) files instead of text files. Or you might want to upload files + parameters (there is a commented example in the code)

The lib posts your form data with a form tag 'payload' and a file name 'temp.txt'

This lib is meant for iOS and Android

This lib uses OKHTTP and CoreProgress Gradle dependecies as well as AFNetworking 3.0 Pod

Usage

OnComplete<CustomNetworkEvent> progressListener = CustomNetworkEvent -> {   
  //track your progress here with CustomNetworkEvent.progres
};
OnComplete<CustomNetworkEvent> doneListener = CustomNetworkEvent -> {   
    //upload finished. response in CustomNetworkEvent.response
};
OnComplete<CustomNetworkEvent> errorListener = CustomNetworkEvent -> {  
    //upload error. You might want to re-try
};
com.javieranton.ProgressUploader.progressDoneCallback = doneListener;
com.javieranton.ProgressUploader.progressCallback = progressListener;
com.javieranton.ProgressUploader.progressErrorCallback = errorListener;
com.javieranton.ProgressUploader.PostMultipart(url, fileContentString);

Server-side example (Node.js + express)

You have to serve a multipart HTTP endpoint (MIME type "multipart/form-data"). This example posts one single text file but your server code will also be different if you decide to go ahead and modify this lib to post multiple files, string params, etc

const Multer = require('multer');
const multer = Multer({
storage: Multer.memoryStorage(),
limits: {
        fileSize: 100 * 1000 * 1000, // no larger than 100mb, you can change as needed.
    }
});
app.post('/YourEndpoint', multer.single('payload'), (req, res) => {
    console.log(req.file.originalname);
    res.send({result:"ok"});
});

progressuploader's People

Contributors

javieranton-zz avatar

Stargazers

 avatar

Watchers

 avatar

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.