Coder Social home page Coder Social logo

Comments (5)

alexbbb avatar alexbbb commented on May 17, 2024

Please post your code so I can help you

from android-upload-service.

droididan avatar droididan commented on May 17, 2024

Ok, Thank.
my main goal is to capture an picture and upload it to the server or choose from the gallery
AsyncTask

private class UploadFileToServer extends AsyncTask<Void, Integer, String> {

    @Override
    protected String doInBackground(Void... params) {
        String responseString = null;

        final UploadRequest request = new UploadRequest(
                getActivity(),
                UUID.randomUUID().toString(),
                "http://file.staging.nuro.im/user_files");

        request.addFileToUpload(filePath.toString(),
                "file",
                filePath.toLowerCase(),
                getMimeType(filePath));


        // Headers data
       i set here my headers...


        //You can add your own custom headers
        request.addHeader("access-token", accessToken);
        request.addHeader("client", client);
        request.addHeader("expiry", expiry);
        request.addHeader("uid", Uid);
        request.addHeader("device_type", "android");
        request.addParameter("channel_id", channelData.getId());

        //configure the notification
        request.setNotificationConfig(android.R.drawable.ic_menu_upload,
                "Uploading secure file",
                "upload in progress text",
                "upload completed successfully text",
                "upload error text",
                false);

        try {
            //Start upload service and display the notification
            UploadService.startUpload(request);

        } catch (Exception exc) {
            //You will end up here only if you pass an incomplete UploadRequest
            Log.e("AndroidUploadService", exc.getLocalizedMessage(), exc);
        }

        return responseString;
    }

    @Override
    protected void onPostExecute(String result) {
        Log.e(TAG, "Response from server: " + result);

        // showing the server response in an alert dialog
        showAlert(result);

        super.onPostExecute(result);
    }
}

from android-upload-service.

alexbbb avatar alexbbb commented on May 17, 2024

I have some remarks to make :D (don't take it personally!):

  • the use of the AsyncTask is totally unnecessary, because Android Upload Service already works entirely in the background, not locking your main UI thread in any way :)
  • the value of responseString will always be null, as you set it only once at the beginning of the method and then you simply return it at the end. To get upload status and the response from the server you have to use the receiver provided with the library (https://github.com/alexbbb/android-upload-service#how-to-monitor-upload-status)

I invite you to check the example app provided with the library. You can compile it and run it on your device. More specifically, look at how the MainActivity is structured: https://github.com/alexbbb/android-upload-service/blob/master/examples/app/src/com/alexbbb/uploadservice/demo/MainActivity.java

from android-upload-service.

droididan avatar droididan commented on May 17, 2024

Hey,

Thanks again :))
I looked at your examples. now i get error message from the FileUpload Class

what i am trying to do:

  1. take a picture or choose from the gallery
  2. get the Uri from the camera or gallery
  3. Send the picture to my server

Error i got when trying to send the image ( i pass the Uri from the camera)
03-05 14:39:30.757 10009-10009/com.nuro E/ChatFragment﹕ Error in upload
with ID: b6edaaf7-6446-4b61-9a11-4f2955dbab56.
/file:/storage/emulated/0/Pictures/Nuro/IMG_20150305_143923.jpg: open
failed: ENOENT (No such file or directory)
java.io.FileNotFoundException:
/file:/storage/emulated/0/Pictures/Nuro/IMG_20150305_143923.jpg: open
failed: ENOENT (No such file or directory)
at libcore.io.IoBridge.open(IoBridge.java:456)
at java.io.FileInputStream.(FileInputStream.java:76)
at
com.alexbbb.uploadservice.FileToUpload.getStream(FileToUpload.java:51)
at
com.alexbbb.uploadservice.UploadService.uploadFiles(UploadService.java:292)
at
com.alexbbb.uploadservice.UploadService.handleFileUpload(UploadService.java:169)
at
com.alexbbb.uploadservice.UploadService.onHandleIntent(UploadService.java:139)
at
android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.os.HandlerThread.run(HandlerThread.java:61)
Caused by: android.system.ErrnoException: open failed: ENOENT (No such
file or directory)
at libcore.io.Posix.open(Native Method)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
at libcore.io.IoBridge.open(IoBridge.java:442)
at java.io.FileInputStream.(FileInputStream.java:76)
at
com.alexbbb.uploadservice.FileToUpload.getStream(FileToUpload.java:51)
at
com.alexbbb.uploadservice.UploadService.uploadFiles(UploadService.java:292)
at
com.alexbbb.uploadservice.UploadService.handleFileUpload(UploadService.java:169)
at
com.alexbbb.uploadservice.UploadService.onHandleIntent(UploadService.java:139)
at
android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.os.HandlerThread.run(HandlerThread.java:61)

This is my code
private void UploadFileToServer(String path) {

    AbstractUploadServiceReceiver uploadReceiver = new

AbstractUploadServiceReceiver() {

        @Override
        public void onProgress(String uploadId, int progress) {
            Log.i(TAG, "The progress of the upload with ID "
                    + uploadId + " is: " + progress);
        }

        @Override
        public void onError(String uploadId, Exception exception) {
            Log.e(TAG, "Error in upload with ID: " + uploadId + ". "
                    + exception.getLocalizedMessage(), exception);
        }

        @Override
        public void onCompleted(String uploadId, int

serverResponseCode, String serverResponseMessage) {
Log.i(TAG, "Upload with ID " + uploadId
+ " has been completed with HTTP " +
serverResponseCode
+ ". Response from server: " +
serverResponseMessage);

            showAlert("Response from server: " + serverResponseMessage);
        }
    };

     uploadReceiver.register(getActivity());


        final UploadRequest request = new

UploadRequest(getActivity(),UUID.randomUUID().toString(),SERVER_ADDRESS);

        request.addFileToUpload(path, "test" ,path,

ContentType.APPLICATION_OCTET_STREAM);

        // Headers data
        String Uid = ((NuroApplication)

getActivity().getApplication()).getNuroApi().headers.getUid();
String accessToken = ((NuroApplication)
getActivity().getApplication()).getNuroApi().headers.getAccessToken();
String client = ((NuroApplication)
getActivity().getApplication()).getNuroApi().headers.getClient();
String expiry = ((NuroApplication)
getActivity().getApplication()).getNuroApi().headers.getExpiry();

        //You can add your own custom headers
        request.addHeader("access-token", accessToken);
        request.addHeader("client", client);
        request.addHeader("expiry", expiry);
        request.addHeader("uid", Uid);
        request.addHeader("device_type", "android");
        request.addParameter("channel_id", channelData.getId());

        //configure the notification
        request.setNotificationConfig(android.R.drawable.ic_menu_upload,
                "Uploading secure file",
                "upload in progress text",
                "upload completed successfully text",
                "upload error text",
                false);
        try {
            //Start upload service and display the notification
            UploadService.startUpload(request);

        } catch (Exception exc) {
            //You will end up here only if you pass an incomplete

UploadRequest
Log.e("AndroidUploadService", exc.getLocalizedMessage(),
exc);
}
}

Best!
Idan

On Thu, Mar 5, 2015 at 12:57 PM, Alex Gotev [email protected]
wrote:

I have some remarks to make :D (don't take it personally!):

  • the use of the AsyncTask is totally unnecessary, because Android
    Upload Service already works entirely in the background, not locking your
    main UI thread in any way :)
  • the value of responseString will always be null, as you set it only
    once at the beginning of the method and then you simply return it at the
    end. To get upload status and the response from the server you have to use
    the receiver provided with the library (
    https://github.com/alexbbb/android-upload-service#how-to-monitor-upload-status
    )

I invite you to check the example app provided with the library. You can
compile it and run it on your device. More specifically, look at how the
MainActivity is structured:
https://github.com/alexbbb/android-upload-service/blob/master/examples/app/src/com/alexbbb/uploadservice/demo/MainActivity.java


Reply to this email directly or view it on GitHub
#23 (comment)
.

Idan Ayalon

from android-upload-service.

alexbbb avatar alexbbb commented on May 17, 2024

From what I see in the stack trace you posted, the problem is that the file /storage/emulated/0/Pictures/Nuro/IMG_20150305_143923.jpg cannot be open (No such file or directory). The problem can be one of those two:

  • you're passing a path to a file or directory which does not exist on the device. Try going to the same path with a file manager app to check if it exists.
  • you have not set the proper permission in your android app manifest to be able to read from internal and external storage (check android docs for that)

The next time you post some code, please use markdown to properly format it, because it's hard to read it :)

However, the problem you're encountering is not a bug in Android Upload Service, so I'm closing this ticket because we're going off topic.

Please tell me if you solved this issue you opened by applying my suggestion: #22

from android-upload-service.

Related Issues (20)

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.