I wanted to upload multiple files in one request. I can upload file to server, but I cann't upload more then one file. here is my code
try { String uploadId = UUID.randomUUID().toString(); uploadReceiver.setDelegate((SingleUploadBroadcastReceiver.Delegate) this); uploadReceiver.setUploadID(uploadId); //Creating a multi part request new MultipartUploadRequest(this, uploadId, UPLOAD_URL) .addFileToUpload(path, "p_url[]") .addParameter("phone_number", phone_number) .addHeader("Authorization", "Bearer " + token) //Adding token .setNotificationConfig(new UploadNotificationConfig()) .setMaxRetries(2) .startUpload(); //Starting the upload } catch (Exception exc) { Toast.makeText(this, exc.getMessage(), Toast.LENGTH_SHORT).show(); } I try to upload image files. This is start image picker
ImagePicker.create(this) .folderMode(true) // set folder mode (false by default) .folderTitle("Folder") // folder selection title .imageTitle("Tap to select") // image selection title .single() // single mode .multi() // multi mode (default mode) .limit(10) // max images can be selected (999 by default) .showCamera(true) // show camera or not (true by default) .imageDirectory("Camera") // captured image directory name ("Camera" folder by default) .origin(images) // original selected images, used in multi mode .start(PICK_FILE_REQUEST); // start image picker activity with request code And Activity result
if (requestCode == PICK_FILE_REQUEST && resultCode == RESULT_OK && data != null) { filePath = data.getData(); images = data.getParcelableArrayListExtra(ImagePickerActivity.INTENT_EXTRA_SELECTED_IMAGES); StringBuilder sb = new StringBuilder(); for (int i = 0; i < images.size(); i++) { Log.d("____IMAGES_____", images.get(i).getPath()); } } Log show this information
D/____IMAGES_____: /storage/emulated/0/DCIM/ios-logo1.png D/____IMAGES_____: /storage/emulated/0/DCIM/Screenshot_1491908860.png D/____IMAGES_____: /storage/emulated/0/DCIM/product_4.png And I try to send multiple file like this
try { String uploadId = UUID.randomUUID().toString(); uploadReceiver.setDelegate((SingleUploadBroadcastReceiver.Delegate) this); uploadReceiver.setUploadID(uploadId); //Creating a multi part request new MultipartUploadRequest(this, uploadId, UPLOAD_URL) .addFileToUpload(path1, "p_url[]") .addFileToUpload(path2, "p_url[]") .addParameter("phone_number", phone_number) .addHeader("Authorization", "Bearer " + token) //Adding token .setNotificationConfig(new UploadNotificationConfig()) .setMaxRetries(2) .startUpload(); //Starting the upload } catch (Exception exc) { Toast.makeText(this, exc.getMessage(), Toast.LENGTH_SHORT).show(); } It is work fine, but I choose files with file chooser. And files count will be dynamical. Above code I get files count static. User selected files, and my programm must to upload all of them