Hello guys, in this post I came up with an easy solution for uploading files from android to server. So today we will see an example of Android Upload Image to Server. I have already posted some example of Android Upload Image to Server previously. But in this post we will use android upload service for our Android Upload Image App.
Check the Updated Android Upload File Tutorial Here
In this tutorial I will store the image file inside servers directory and in database I will store the URL of the image. For this I will use Android Upload Service library and it makes uploading files super easy. So lets see how we can do it. First we will create our server side codes.
Android Upload Image to Server Video Tutorial
- You can also go through this video tutorial to learn how to upload image from android to server.
Creating Server Side Codes for Android Upload Image
The first thing we need is to create our server side web services. For server side I am using PHP and MySQL. And for this I am using Wamp server. You can still use xampp or any other application. Now follow the steps to create your web service to handle the file upload.
- Go to localhost/phpmyadmin and create the following database table.
- Now inside your server’s root directory (c:/wamp/www) and create a new folder. I created AndroidUploadImage.
- Inside the folder create a folder named uploads, in this folder we will save all the uploaded images.
- Create a file named dbDetails.php and write the following code.
1 2 3 4 5 6 7 | <?php define('HOST','localhost'); define('USER','root'); define('PASS',''); define('DB','db_images'); |
- Now create a file named upload.php and write the following code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | <?php //importing dbDetails file require_once 'dbDetails.php'; //this is our upload folder $upload_path = 'uploads/'; //Getting the server ip $server_ip = gethostbyname(gethostname()); //creating the upload url $upload_url = 'http://'.$server_ip.'/AndroidImageUpload/'.$upload_path; //response array $response = array(); if($_SERVER['REQUEST_METHOD']=='POST'){ //checking the required parameters from the request if(isset($_POST['name']) and isset($_FILES['image']['name'])){ //connecting to the database $con = mysqli_connect(HOST,USER,PASS,DB) or die('Unable to Connect...'); //getting name from the request $name = $_POST['name']; //getting file info from the request $fileinfo = pathinfo($_FILES['image']['name']); //getting the file extension $extension = $fileinfo['extension']; //file url to store in the database $file_url = $upload_url . getFileName() . '.' . $extension; //file path to upload in the server $file_path = $upload_path . getFileName() . '.'. $extension; //trying to save the file in the directory try{ //saving the file move_uploaded_file($_FILES['image']['tmp_name'],$file_path); $sql = "INSERT INTO `db_images`.`images` (`id`, `url`, `name`) VALUES (NULL, '$file_url', '$name');"; //adding the path and name to database if(mysqli_query($con,$sql)){ //filling response array with values $response['error'] = false; $response['url'] = $file_url; $response['name'] = $name; } //if some error occurred }catch(Exception $e){ $response['error']=true; $response['message']=$e->getMessage(); } //displaying the response echo json_encode($response); //closing the connection mysqli_close($con); }else{ $response['error']=true; $response['message']='Please choose a file'; } } /* We are generating the file name so this method will return a file name for the image to be upload */ function getFileName(){ $con = mysqli_connect(HOST,USER,PASS,DB) or die('Unable to Connect...'); $sql = "SELECT max(id) as id FROM images"; $result = mysqli_fetch_array(mysqli_query($con,$sql)); mysqli_close($con); if($result['id']==null) return 1; else return ++$result['id']; } |
- Now test your script. You can use a rest client to test it I am using POSTMAN. See the below screenshot.
- If you are seeing the above response then. Your script is working fine. You can check the database and upload folder which you have created.


- So its working absolutely fine. Now lets move ahead and create a android project.
Creating Android Studio Project
We are done with the server side coding for this Android Upload Image Example. Now lets code our android application. Follow the steps given.
- Create a Android Studio Project.
- Create a class named Constants.java and write the following code. The following class contains the path to our php file which we created. You are seeing two strings. The second it the path to the file we will create at the end of this post.
1 2 3 4 5 6 7 8 9 10 11 | package net.simplifiedcoding.androidimageupload; /** * Created by Belal on 6/10/2016. */ public class Constants { public static final String UPLOAD_URL = "http://192.168.94.1/AndroidImageUpload/upload.php"; public static final String IMAGES_URL = "http://192.168.94.1/AndroidImageUpload/getImages.php"; } |
- You need to change the IP according to your system. To know the IP you can use IPCONFIG command in command prompt (windows user).
- Now we need to add android upload service to our project.
Adding Android Upload Service
- Go to your app level build.gradle file and add the following line inside dependencies block and sync your project.
1 2 3 4 5 6 7 8 9 10 | dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.4.0' //Add this line compile 'net.gotev:uploadservice:2.1' } |
- Come to activity_main.xml and write the following xml code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="net.simplifiedcoding.androidimageupload.MainActivity"> <LinearLayout android:gravity="center_horizontal" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <Button android:id="@+id/buttonChoose" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Select" /> <EditText android:id="@+id/editTextName" android:hint="Name For Image" android:layout_weight="1" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <Button android:id="@+id/buttonUpload" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Upload" /> </LinearLayout> <ImageView android:id="@+id/imageView" android:layout_width="match_parent" android:layout_height="match_parent" /> </LinearLayout> |
- The above code will generate the following layout.
- As you can see we have two buttons, one to select image and other to upload image. We also have an EditText to enter the name for the image.
- Now come to MainActivity.java and write the following code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | package net.simplifiedcoding.androidimageupload; import android.Manifest; import android.content.Intent; import android.content.pm.PackageManager; import android.database.Cursor; import android.graphics.Bitmap; import android.net.Uri; import android.os.Bundle; import android.provider.MediaStore; import android.support.annotation.NonNull; import android.support.v4.app.ActivityCompat; import android.support.v4.content.ContextCompat; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.ImageView; import android.widget.Toast; import net.gotev.uploadservice.MultipartUploadRequest; import net.gotev.uploadservice.UploadNotificationConfig; import java.io.IOException; import java.util.UUID; public class MainActivity extends AppCompatActivity implements View.OnClickListener { //Declaring views private Button buttonChoose; private Button buttonUpload; private ImageView imageView; private EditText editText; //Image request code private int PICK_IMAGE_REQUEST = 1; //storage permission code private static final int STORAGE_PERMISSION_CODE = 123; //Bitmap to get image from gallery private Bitmap bitmap; //Uri to store the image uri private Uri filePath; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //Requesting storage permission requestStoragePermission(); //Initializing views buttonChoose = (Button) findViewById(R.id.buttonChoose); buttonUpload = (Button) findViewById(R.id.buttonUpload); imageView = (ImageView) findViewById(R.id.imageView); editText = (EditText) findViewById(R.id.editTextName); //Setting clicklistener buttonChoose.setOnClickListener(this); buttonUpload.setOnClickListener(this); } /* * This is the method responsible for image upload * We need the full image path and the name for the image in this method * */ public void uploadMultipart() { //getting name for the image String name = editText.getText().toString().trim(); //getting the actual path of the image String path = getPath(filePath); //Uploading code try { String uploadId = UUID.randomUUID().toString(); //Creating a multi part request new MultipartUploadRequest(this, uploadId, Constants.UPLOAD_URL) .addFileToUpload(path, "image") //Adding file .addParameter("name", name) //Adding text parameter to the request .setNotificationConfig(new UploadNotificationConfig()) .setMaxRetries(2) .startUpload(); //Starting the upload } catch (Exception exc) { Toast.makeText(this, exc.getMessage(), Toast.LENGTH_SHORT).show(); } } //method to show file chooser private void showFileChooser() { Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE_REQUEST); } //handling the image chooser activity result @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK && data != null && data.getData() != null) { filePath = data.getData(); try { bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), filePath); imageView.setImageBitmap(bitmap); } catch (IOException e) { e.printStackTrace(); } } } //method to get the file path from uri public String getPath(Uri uri) { Cursor cursor = getContentResolver().query(uri, null, null, null, null); cursor.moveToFirst(); String document_id = cursor.getString(0); document_id = document_id.substring(document_id.lastIndexOf(":") + 1); cursor.close(); cursor = getContentResolver().query( android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, null, MediaStore.Images.Media._ID + " = ? ", new String[]{document_id}, null); cursor.moveToFirst(); String path = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DATA)); cursor.close(); return path; } //Requesting permission private void requestStoragePermission() { if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) return; if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.READ_EXTERNAL_STORAGE)) { //If the user has denied the permission previously your code will come to this block //Here you can explain why you need this permission //Explain here why you need this permission } //And finally ask for the permission ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, STORAGE_PERMISSION_CODE); } //This method will be called when the user will tap on allow or deny @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { //Checking the request code of our request if (requestCode == STORAGE_PERMISSION_CODE) { //If permission is granted if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { //Displaying a toast Toast.makeText(this, "Permission granted now you can read the storage", Toast.LENGTH_LONG).show(); } else { //Displaying another toast if permission is not granted Toast.makeText(this, "Oops you just denied the permission", Toast.LENGTH_LONG).show(); } } } @Override public void onClick(View v) { if (v == buttonChoose) { showFileChooser(); } if (v == buttonUpload) { uploadMultipart(); } } } |
- Finally add the storage and internet permission on your manifest.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="net.simplifiedcoding.androidimageupload"> <!-- add these permissions --> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> |
- Thats it now just run your app.
- Bingo! Its working absolutely fine. Now you may need to fetch the uploaded images.
Fetching the Uploaded Images
- To fetch the images inside your server side project, create one more file named getImages.php and write the following code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | <?php //Importing dbdetails file require_once 'dbDetails.php'; //connection to database $con = mysqli_connect(HOST,USER,PASS,DB) or die('Unable to Connect...'); //sql query to fetch all images $sql = "SELECT * FROM images"; //getting images $result = mysqli_query($con,$sql); //response array $response = array(); $response['error'] = false; $response['images'] = array(); //traversing through all the rows while($row = mysqli_fetch_array($result)){ $temp = array(); $temp['id']=$row['id']; $temp['name']=$row['name']; $temp['url']=$row['url']; array_push($response['images'],$temp); } //displaying the response echo json_encode($response); |
- This code will give you the following JSON.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | { "error":false, "images":[ { "id":"1", "name":"Belal Khan", "url":"http:\/\/192.168.94.1\/AndroidImageUpload\/uploads\/1.jpg" }, { "id":"2", "name":"Belal", "url":"http:\/\/192.168.94.1\/AndroidImageUpload\/uploads\/2.jpg" }, { "id":"3", "name":"", "url":"http:\/\/192.168.94.1\/AndroidImageUpload\/uploads\/3.jpg" }, { "id":"4", "name":"Belal Khan", "url":"http:\/\/192.168.94.1\/AndroidImageUpload\/uploads\/4.jpg" } ] } |
- Now you can use the following tutorial to display the images using the above JSON.
Android Custom GridView with Images and Texts using Volley
- You can also get my source code from the link given below.
So thats it for this Android Upload Image tutorial friends. You can also use this method to upload video and any type of file to your server. Leave your comments if having any doubts or feedbacks. Thank You 🙂

Hi, my name is Belal Khan and I am a Google Developers Expert (GDE) for Android. The passion of teaching made me create this blog. If you are an Android Developer, or you are learning about Android Development, then I can help you a lot with Simplified Coding.
Assala-mualikum, This is a best tutorial for upload image(base64) to server using volley library. Its done well. Now I want to upload pdf to use base64——– I want know is that possible to upload pdf base64?? ………… If possible I request you to upload a tutorial for pdf upload. Thank you for your great tutorial. Happy Ramadan…
“Oops you just denied the permission” this message is displaying,images are not uploading,how to slove this.
Add permissions to manifest file.
If on server side check username and password.
how to check username and password on server
Your Code is working fine..i can able to upload image…only thing i couldnt able to upload parameter
addParameter(“id”, uniqueid) //Adding text parameter to the request
//php side
$unique_id= $_POST[‘id’];
“Oops you just denied the permission” this toast is displaying ,images are not uploading
follow same tutorial but Error during upload occur in notification…why?
1. check that u have put tyour internet permission in manifest
2. Check that your upload url is correct
Ya, I have the same problem. Why? I have checked with the upload url and also the internet permission already.
Oops you just denied the permission how to resolve these,pls help me .
deined permission message is displaying how to slove these
nice article (y)
sir,, can i request tutorial about how to implement Single Sign-On Android??
thank u sir 🙂
Amazing tutorial guys It came exactly when I needed it to build upload for our app .. Fliiby << 🙂 will be live from July I hope 🙂
I did a lot of modifications like loading images with glide since loading bitmap is memory heavy.. text immediately started lagging when I load 4-5mb picture.. changed notifications system etc… but guys thanks again it helped me a lot..
==glide change for image=====
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK && data != null && data.getData() != null) {
filePath = data.getData();
Glide.with(getApplicationContext())
.load(filePath)
.diskCacheStrategy(DiskCacheStrategy.ALL)
// .fitCenter()
.centerCrop()
.crossFade(500)
.priority(Priority.HIGH)
.into(imageView);
}
}
Hi Belal,
I am following your tutorials and these are very helpful for me, Thank you for tutorials.
I want the code for downloading pdf file which is stored in my database.
Could you please write the code and upload it for me.
How to upload the image that is captured with camera within the android application,, im getting trouble please help….
Belal Khan your tutorial is fantastic. It is easy to comprehend and implement. However I am getting this error in the error log in the server
“mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in /…………../AndroidUploadImage/upload.php on line 78”
I am using postman exactly as you show and I am getting no responce and status 200 OK.
What could be the issue here?
Thanks in advance.
PS. In your tutorial you use AndroidUploadImage, but in your code you use AndroidImageUpload. Some people will scratch their head if they copy the code and find out it doesn’t work.
name and url are uploaded in mysql. but image is not uploading in the folder when i run the php code in postman.
I had the same error and what i did is to copy any image that you have and paste it in that folder and name it with the previous id, for example if your last register in database is 12 that image have to have that number, and now try to do upload again a picture using the app and it might work.
1.Check if the client has necessary permission for uploading files.
2.Check your PHP Configuration File To Check File Size Upload Limit/No Of Files/Temp Directory and Change according to your requirement.
its not able to connect the http server
getting the error on android device. File Upload Error during upload
Everything is working well for me, except one thing. supposing someone chooses not to select an image for upload, but clicks the upload button, the app crashhes! How do I prevent the app from crashing? prompting the user “please select an image”
Have you found any solution?
It’s a pity … The upload is done but the pictures do not advance to the uploads folder. What should be done ?
Error in line 79 :
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in C:\wamp\www\phpcode\upload.php on line 79
you did not pass the id
I have doubts to upload the audio on server. plz help me
bas bhai aise hi kam kiya kar..osm
Thanks!!!
Very helpful
I am getting error while uploading …is error in upload at notification area.
Have you found any solution?
i can ‘t get the file path from the gallery application keeps crashing when i i try to upload . Error on the console shows that the method getpath() is not returning the image
No longer working in Android 6.0
You need to ask storage permission at run time to make it work on >android 5
Check this tutorial to know how https://www.simplifiedcoding.net/android-marshmallow-permissions-example/
Hello Belal. I got error Please choose a file in Postman. Please help
getMessage();
}
//displaying the response
echo json_encode($response);
//closing the connection
mysqli_close($con);
} else {
echo $response[‘error’]=true;
echo $response[‘message’]=’Please choose a file’;
}
}
/*
We are generating the file name
so this method will return a file name for the image to be upload
*/
function getFileName(){
$sql = “SELECT max(notesID) as notesID FROM notes”;
$result = mysqli_fetch_array(mysqli_query($con,$sql));
mysqli_close($con);
if($result[‘notesID’]==null)
return 1;
else
return ++$result[‘notesID’];
}
?>
sorry the code went crazy. here in pastebin http://pastebin.com/MygkttBm
I tried the php code in POSTMAN and everything is fine and i tried the code in android studio and it is working fine but once i upload the image, i get this “Error during upload”. please help
I used the same method for uploading image into filezilla server. Everything is fine but the image is not uploading into the folder created in filezilla. can you please help me?
Hello Bilal,
I followed your tutorial and uploads are going through(even a 5 mb image goes through successfully. However, when i uppload another image, it overwrites the previous image. The first image was uploaded as 1.jpg. Then I uploaded a .png file and it was saved as 1.png. But when I try uploading more jpg files, it only overwrites and does not increment the number to 2 and so on. I also noticed my table returns no rows after this. Any help is appreciated. Thanks.
Hi Rakesh
I am too Stuck on This Do You find the Solutions What Wrong here….Do you have any notions how to calculate response from server in the activity
hi, i meet a same problem, and i find the it can be solve just through modify some segment.
i modify code in line 33-40 to:
// getting the file filename
$filename = $fileinfo[‘filename’];
//getting the file extension
$extension = $fileinfo[‘extension’];
//file url to store in the database
$file_url = $upload_url . $filename . ‘.’ . $extension;
//file path to upload in the server
$file_path = $upload_path . $filename . ‘.’. $extension;
these code segment let picture save use thire own filename, as if your picture named “boy.jpg”, it will upload to “AndroidImageUpload/uploads” with its own name “boy.jpg”.
Hi Mr. Belal!
I appreciate your tutorial so much and it has helped me to build a good android app which I will be asking you to download and assess for improvement.
I an using this example to upload an image but I don’t want the image to be displayed on the activity but the filepath to be set on the edittext. In the process, I realised that you are not setting the filepath on the edittext.
Kindly check you observation and respond.
Thanks and regards.
hey!
i want to upload a image to asp.net server
i want to know the server side code also.
Why i am getting my image compressed?
can you give me idea?
its not the same size size i uploaded.
What if 2 or more than 2 user upload images with same name like 1.jpg then how can we differentiate in them?
Nice tutorial, one question, how do you set headers for authorization in this method?
Thanks Bro You are my saviour.
and once again thank u very very very very very very very very very very very very much
How to Upload file in Jsonobject with upload service
Hi,
Belal sir ,i am using image upload but some error to solution is tough in ,i am copy our website but no solution please help image upload in android studio
Warning: move_uploaded_file() [
function.move-uploaded-file]: It is not safe to rely on the system’s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected ‘Asia/Calcutta’ for ‘IST/5.0/no DST’ instead in
/home/celeadmn/public_html/demo/upload.php on line
31
Warning: move_uploaded_file(uploads/12.html) [
function.move-uploaded-file]: failed to open stream: No such file or directory in
/home/celeadmn/public_html/demo/upload.php on line
31
Warning: move_uploaded_file() [
function.move-uploaded-file]: It is not safe to rely on the system’s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected ‘Asia/Calcutta’ for ‘IST/5.0/no DST’ instead in
/home/celeadmn/public_html/demo/upload.php on line
31
Warning: move_uploaded_file() [
function.move-uploaded-file]: Unable to move ‘/tmp/phpUbekSp’ to ‘uploads/12.html’ in
/home/celeadmn/public_html/demo/upload.php on line
31
{“error”:false,”url”:”http:\/\/www.celebritiesacademy.com\/Androidimageupload\/uploads\/12.html”,”name”:”aafhyh”}
ok clear you check to commend line to write cmd and you set ipconfig/all ,
Ex : http://192.168.143.2/AndroidImageUpload/upload.php // ip you = 192.168.143.2
pic: http://upload.i4th.in.th/th/download.php?id=587363531
you ok
Social : Android Developer Library GitHub
: https://www.facebook.com/groups/883546485084033/?fref=ts
Hi Belal ,
You have an awesome website and more than that you are an awesome blog writer because of the efforts that you are taking.
I have been using your code for some time now.
I would love to see a tutorial from you on same thing as https://www.simplifiedcoding.net/android-volley-tutorial-to-upload-image-to-server/
but i want to be able to use camera as well.
Thank you for making world a great place.
How to get JSON Object Response message when it Success or Failure , Thank you 😀
Hy Belal , thank you
this tutorial work for me , but how i can get Json Object
request
to notify me in activity when upload image is succes or failureHi Belal khan
Thanks because of your perfect codes
i run this code bud i have problem with upload and error with upload
i check every thing more and more but i’m going to crazy
please help me
Hi, belal..
This code is very helpfull, i want to know about if i want to upload more than 1 file in 1 proccess
Thanks
you create code java method more to send image and you edit for
new MultipartUploadRequest(this, uploadId, Constants.UPLOAD_URL)
.addFileToUpload(path, “image”) //Adding file
.addParameter(“name”, name) //Adding text parameter to the request
.setNotificationConfig(new UploadNotificationConfig())
.setMaxRetries(2)
.startUpload();
to
new MultipartUploadRequest(this, uploadId, Constants.UPLOAD_URL)
.addFileToUpload(path, “image”) //Adding file
.addFileToUpload(path, “image”)
.addFileToUpload(path, “image”)
.addFileToUpload(path, “image”)
.
.
.
to
new MultipartUploadRequest(getContext(), uploadId, Constants.UPLOAD_URL)
.addFileToUpload(path, “image”) //Adding file
.addFileToUpload(path, “image”) //Adding file
.addFileToUpload(path, “image”) //Adding file
.addFileToUpload(path, “image”) //Adding file
.addParameter(“pea_id”, pea_id) //Adding text parameter to the request
.addParameter(“name”,URLEncoder.encode(inspect, “UTF-8”))
.addParameter(“latitude”, Latitude)
.addParameter(“longitude”, Longitude)
.addParameter(“description”,URLEncoder.encode(ValueHolderSpinner, “UTF-8”))
.addParameter(“date”, date)
.setNotificationConfig(new UploadNotificationConfig())
.setMaxRetries(2)
.startUpload(); //Starting the upload
how can i show successfully uploaded message in my activity
How to shrink teh size image before upload ? Please help me
How do I send two simultaneous images? What changes will be made to the php code? Thank you
How to compress image before upload ?
one i click on upload button it’s showing error ” Unfortunately AndroidImageUpload has stopped work.
Sir thank u so much, only you made it possible,
i tried number of methods tutorials but no one helped and you just wrote the code in such a simplified manner that beginners like us can understand very easily moreover you made this possible to upload the images to server otherwise many of us were in trouble to how to upload images to server i will follow you everywhere nowonwards , such a great help to me for making my minor project .
thank u so much sir!
Hello Belal, Would there be a possibility to upload two images and assign them names instead of incrementing numbers? If so, how to proceed on the PHP file?
How to upload songs(mp3) to the xampp server?
using this methods
Pls provide a query for creating table in MySql….it will make it easy to use
Hi , can u just mail me ( mlrohit6@gmail.com )the complete zip file of this project. I downloaded the project zip from your blog but i cant find the some java files .
worked like charm
Hi Belal,
Thankyou for Tutorial,
How to Delete uploaded image in mysql and server (host)with android app?
Hello Sir, I have an error in this code is if we run this without validation means if we not select any file then it asking please select file and data cannot be submitted but i want to make a choice for the user that if user wants to select image or if user not want then it skip but the data will be submitted but this tsk is not performed..
Hello , my name muhajir from indonesian , i want to ask , how to multiple upload file using library upload service ?
thanks
error during upload ..why ??
Upload success but data not inserted in database
In the notification bar I’m getting an error during upload. Has anyone solved this issue? Can someone please help me with this? Many thanks.
Please sir ,I want to know how to upload image on a cpanel server ….i am fresher in an company
hello sir ur program is showing cursor out of bound exception:
Have you tried downloading my code?
Where is service?
Android Upload Service is the name of the library we are using here
Hey Belal,
Thank you the tutorial but I am having some trouble getting it running. When I hit upload, the app crashes. After some inspection, it seems the cursor in getPath() is empty. This is the redefinition of the cursor that is empty, so the cursor defined as: cursor = getContentResolver().query(
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
null, MediaStore.Images.Media._ID + ” = ? “, new String[]{document_id}, null);
I’m not sure how to fix this. Any help would be much appreciated!
new MultipartUploadRequest(this, uploadId, SyncStateContract.Constants.UPLOAD_URL)
here in above line UPLOAD_URL shows error.I make class constants but it is showing that it is never used.
hey! nice post!
I’m trying to upload an image from gallery, I’ve allready tested the php on Postman and succesfully upload an Image in my server and updated my DataBase.
When it comes to android……
try {
String uploadId = UUID.randomUUID().toString();
new MultipartUploadRequest(this, uploadId, URL_PHP”)
.addFileToUpload(path, “image”) //Tomar archivo
.addParameter(“name”, name) //guardar parametro nombre
.setNotificationConfig(new UploadNotificationConfig())//notificacion en barra para carga
.setMaxRetries(2)
.startUpload(); //Iniciar la carga
Toast.makeText(this, “si tomo el archivo y si lo busco en php”, Toast.LENGTH_SHORT).show();
} catch (Exception exc) {
Toast.makeText(this, exc.getMessage(), Toast.LENGTH_SHORT).show();
}
The app is showing how the file is uploading, but when it finishes… the notification is: “Error during Upload”
where am I wrong?
Im testing on android 5.1
Using packet Capture…… it throws:
HTTP/1.1 403 Forbidden
How can I fix it?
Nice Work Bro. Thank you
I’m trying to use this code in fragment but I’m getting error “cannot resolve symbol MultipartUploadRequest” , “cannot resolve symbol UploadNotificationConfig” and “cannot resolve symbol UPLOAD_URL” in
public void uploadMultipart() {
//getting name for the image
String name = FullName.getText().toString().trim();
//getting the actual path of the image
String path = getPath(filePath);
//Uploading code
try {
String uploadId = UUID.randomUUID().toString();
//Creating a multi part request
new MultipartUploadRequest(getActivity().getApplicationContext(), uploadId, SyncStateContract.Constants.UPLOAD_URL)
.addFileToUpload(path, “image”) //Adding file
.addParameter(“name”, name) //Adding text parameter to the request
.setNotificationConfig(new UploadNotificationConfig())
.setMaxRetries(2)
.startUpload(); //Starting the upload
} catch (Exception exc) {
Toast.makeText(getActivity().getApplicationContext(), exc.getMessage(), Toast.LENGTH_SHORT).show();
}
}
compile ‘net.gotev:uploadservice:2.1’
I followed every step very carefully around 5-7 times, but not able to upload image. I have Ubuntu 16 server. I tried with Postman that is also not working for me. I really need help.
In Php file If I write print_r($_POST); it show everything is perfect in $_POST, but when we get $_POST[‘name’] and other values, they comes as empty. Means print_r($_POST[‘name’]); prints nothing.
Can anyone help
Great Thanks.
Belal I want to show the response message in alert dialog. I don’t want Notification config how can i do this. Please help
hey! I want same thing to upload audio file so which changes are required for this
hello i am getting error like “Error During Upload” but dnt know how to recove this
Have you found any solution?
I NEED THE SERVER RESPONSE…
where is below link bro.. ? There is no L:ink Shown..
If i will upload the image in mylocal host server, how to find out that image file in my host?
Hi bro Thanks I follow your tutorials it help alot and I learn more things and coding techniques I have one question if you can can make tutorials on it its very important and helpful for others
My question:
I have follow this tutorial and I have done my task but I want to run this application on my android mobile and I send all data from Mobile to laptop, Laptop use as server I am use wamp so is that possible, if so please make tutorial and show to send run same application on mobile and all data send from mobile to laptop instead of emulator using Wifi connection
i am follow same process but image view in same image show on time choose but the upload time they did not choose time image but upload in another image please help us
hello
i am using windows.i dont have postman.what are the alternatives for postman to run the code??
you can install postman in windows too.
if image size is exceeded from 4MB then code not working. any other solution…
Hello, nice article but i faced problem when use setNotificationConfig the error like (android.app.RemoteServiceException: Bad notification for startForeground: java.lang.RuntimeException: invalid channel for service notification). How to fix it please…
I have the same error !
How can i resize the image before uploading to the server ?
i want to put this in asynctask …
what should i have to do ?
Great job sir. It is too much helpful. Now my next step is to display the data in another activity. As the user click on the item from recyclerview all the data of selected item must be displayed in other activity. I only show Name and Image in the recyclerview. and want to display all of its data in other activity. How to do that?
Check this video in my channel to know how
https://www.youtube.com/watch?v=73Vg1HnMoHI&list=PLk7v1Z2rk4hgNu5zXbGctiCWYebxjdeey&index=21
when i try to upload picture, it only show me notification saying Error during upload
Upload button not work please explain how resolve
Hi hello
Did you solve the issue even i am facing the same problem. The button is working fine in the emulator but when I build an apk and install in mobile that time button it is not working. Please help.
Thank you.
This code is not working for Pie version. So please help me.
I have problem with getPath function. I have copy paste your code, but it force close when i click button upload
hai belal, iam alrdy to share your post, but the donload button is error
can you fix or send me sourecode to my email?
my email : satrialin34@gmail.com
thanks belal
Hey Belal, when i tried it on postman it shows this error how to fix it, i copying all of your codes and i dont know why it ‘s just error
here’s the error :
Warning: move_uploaded_file(uploads/4.PNG): failed to open stream: No such file or directory in
D:\xampp\htdocs\opr57\upload.php on line
45
Warning: move_uploaded_file(): Unable to move ‘D:\xampp\tmp\php5602.tmp’ to ‘uploads/4.PNG’ in
D:\xampp\htdocs\opr57\upload.php on line
45
{“error”:false,”url”:”http:\/\/192.168.43.149\/opr57\/uploads\/4.PNG”,”name”:”Bayu”}
Hello, i want to ask about something sir, when i upload it it says “Upload completed successfully” but there’s no image or data on my table, can you help me?
I’ve same issue with you, and dont know how to fix it
Hi Belal,
I have one error if i can run the application in android 8 and above. If i trigger the upload function error will be generated. That error is Bad Request Foreground Notification. Please give any correct solution.
Thanks and regards
Hello and thank you for this tutorial
I’ve used the 4.5.1 version of net.gotev:uploadservice
and i’m getting an error in :
request.setNotificationConfig(new UploadNotificationConfig())
the constructor of UploadNotificationConfig needs 6 parameters
What shoud I do ?
6 arguments needed in new UploadNotificationconfig()
I will check and update the post soon.
And I have already posted an article that do not uses this library. You can check it here:
https://www.simplifiedcoding.net/android-upload-file-to-server/
Hi Belal
No doubt your tutorials are great, can u modify the code or share us how to do upload with 4.5.1 specially due to change in UploadNotificationConfig, 2.6 does not support in latest android. Pls suggest how to set notification configuration as w/o this, i can not upload image.
Code Error
E/MemoryLeakMonitorManager: MemoryLeakMonitor.jar is not exist!
E/AwareLog: AtomicFileUtils: readFileLines file not exist: android.util.AtomicFile@b67bb73
E/AwareLog: AtomicFileUtils: readFileLines file not exist: android.util.AtomicFile@43a0a30
While using Android x library and API level 30
hi sir!
thanks for your tutorial.
i am getting an error in the app when i try to upload an image.
the error is, specify iether http or https as protocol
how can i fix this problem sir?
i am using this code in android 8.0
thanks in advance!