Comments (5)
Please post your code so I can help you
from android-upload-service.
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.
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.
Hey,
Thanks again :))
I looked at your examples. now i get error message from the FileUpload Class
what i am trying to do:
- take a picture or choose from the gallery
- get the Uri from the camera or gallery
- 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.
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)
- Initial notification ignores custom notificationHandlerFactory HOT 7
- Stop Observing from RequestObserver using unregister causing a crash. HOT 3
- Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent. HOT 6
- Google Play will soon require that apps target API level 33 or higher. This will be required for new apps and updates starting on August 31, 2023. HOT 4
- Single notification about all ongoing uploads HOT 3
- Please add support for Android 34 HOT 4
- Java Code Samples? HOT 1
- How to get uploaded file infomation that returned by service api
- Question: Is it possible to send a HTTP request once an upload task finishes? HOT 5
- Question on crash message when closing the app: Unable to create service net.gotev.uploadservice.UploadService HOT 16
- Missing default constructor for SchemeHandler classes HOT 3
- Incompatible version of Kotlin error after upgrading to 4.9.2 HOT 3
- register gotev receiver HOT 2
- Result of uploading file HOT 1
- Bitrise CI Build Failing with New Version HOT 1
- Re-implementation using WorkManager HOT 2
- Android Upload Service for KMM (Koltin Multiplateform) HOT 2
- Add contentType to addParameter HOT 3
- SDK 34 Play Store Rejected without video of FOREGROUND_SERVICE_DATA_SYNC functionality HOT 4
- duplicate uploadID HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from android-upload-service.