Giter Site home page Giter Site logo

seifhjh / androiduploadmanager Goto Github PK

View Code? Open in Web Editor NEW
2.0 0.0 1.0 154 KB

Easily upload files in the background with Event Listener

Home Page: https://seifhjh.github.io/AndroidUploadManager/

License: Apache License 2.0

Java 100.00%
android android-studio upload uploader upload-file upload-images upload-pictures upload-videos upload-manager ftp

androiduploadmanager's Introduction

N|Solid

Android Upload Manager

ScreenShot

N|Solid

Download

Step 1. Add the JitPack repository to your build file
allprojects {
	repositories {
		...
		maven { url 'https://jitpack.io' }
	}
}
Step 2. Add the dependency
dependencies {
implementation 'com.github.seifhjh:AndroidUploadManager:1.2.0'
}

How to use

Client (Android)

 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        UploadManager.urlServer="http://host/uploadFile";
    }

One file

 UploadManager.uploadFileFromFile(getApplicationContext(), file, new UploadManager.OnProgressListener() {
            @Override
            public void onProgress(long percent) {
                Log.e(TAG,"onProgress : "+percent);
            }

            @Override
            public void onComplite(String response) {
                Log.e(TAG,"onComplite : "+response);
            }

            @Override
            public void onFailed(Throwable error) {
                Log.e(TAG,"onFailed : "+error.getMessage());
            }
        });

Multi files

  List<File> listFiles=new ArrayList<>();
        listFiles.add(file);
        listFiles.add(file);
        UploadManager.uploadFileFromFile(getApplicationContext(), listFiles, new UploadManager.OnProgressMultiListener() {
            @Override
            public void onProgress(long percent) {
                Log.e(TAG,"onProgress : "+percent);
            }

            @Override
            public void onComplite(List<String> listResponse) {
                Log.e(TAG,"onComplite : "+listResponse);
            }

            @Override
            public void onFailed(Throwable error) {
                Log.e(TAG,"onFailed : "+error.getMessage());
            }
        });

Server

<?php
include "conn.php";
try{
    $name = time();
    $path = $_FILES['file']['name'];
    
    $ext = pathinfo($path, PATHINFO_EXTENSION);
    $stored_name ="file-$name.$ext";
    if (!file_exists('path/file')) {
        mkdir('path/file/', 0777, true);
        }
        
    if(move_uploaded_file($_FILES['file']['tmp_name'],"path/file/$stored_name"))
    {
        mime_content_type('path/file/'.$stored_name);

        $result=array(
            'master'=>array(
            'etat' => "succes",
            'url'=> "$host/path/file/$stored_name"
            ));
    }else{
        $result=array(
            'master'=>array(
            'etat' => "failure",          
            'url'=> "$host/path/file/profil-default.jpg"
            ));
    }

    echo json_encode($result);

}catch(Exception $e){
  
}		

?>

Output

{
"master":
{"etat":"succes","url":"http:\/\/host\/path\/file\/file-1563922243.mp4"}
}

Full Example

MainActivity.java

Developer

Seif Hadjhassen - Github
Seif Hadjhassen - Linked In
Seif Hadjhassen - Facebook
Seif Hadjhassen - Twitter
Seif Hadjhassen - Dribbble
Seif Hadjhassen - Pinterest

License

  Copyright 2019 Seif Hadjhassen

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

androiduploadmanager's People

Contributors

seifhjh avatar

Stargazers

 avatar  avatar

Forkers

nikhil-z

androiduploadmanager's Issues

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.