Search in sources :

Example 1 with FileOutputStreamRouter

use of com.backendless.files.router.FileOutputStreamRouter in project Android-SDK by Backendless.

the class UploadFileAsyncTask method doInBackground.

private void doInBackground(final File file, final String path) {
    final AsyncUploadMessage asyncUploadMessage = new AsyncUploadMessage(uploadCallback);
    ThreadPoolService.getPoolExecutor().execute(new Runnable() {

        @Override
        public void run() {
            try {
                FileOutputStreamRouter fileOutputStreamRouter = new FileOutputStreamRouter(file, new UploadCallback() {

                    public void onProgressUpdate(Integer progress) {
                        asyncUploadMessage.setCurrentProgress(progress);
                        ResponseCarrier.getInstance().deliverMessage(asyncUploadMessage);
                    }
                });
                BackendlessFile result = Backendless.Files.uploadFromStream(fileOutputStreamRouter, file.getName(), path, overwrite);
                ResponseCarrier.getInstance().deliverMessage(new AsyncMessage<BackendlessFile>(result, responder));
            } catch (Exception e) {
                ResponseCarrier.getInstance().deliverMessage(new AsyncMessage<BackendlessFile>(new BackendlessFault(e), responder));
            }
        }
    });
}
Also used : AsyncUploadMessage(com.backendless.async.message.AsyncUploadMessage) UploadCallback(com.backendless.async.callback.UploadCallback) AsyncMessage(com.backendless.async.message.AsyncMessage) FileOutputStreamRouter(com.backendless.files.router.FileOutputStreamRouter) BackendlessFile(com.backendless.files.BackendlessFile) BackendlessFault(com.backendless.exceptions.BackendlessFault)

Aggregations

UploadCallback (com.backendless.async.callback.UploadCallback)1 AsyncMessage (com.backendless.async.message.AsyncMessage)1 AsyncUploadMessage (com.backendless.async.message.AsyncUploadMessage)1 BackendlessFault (com.backendless.exceptions.BackendlessFault)1 BackendlessFile (com.backendless.files.BackendlessFile)1 FileOutputStreamRouter (com.backendless.files.router.FileOutputStreamRouter)1