Closed ihazar closed 5 years ago
@ihazar what API level is your emulator/device? Try removing the node_modules
, platforms
and hooks
folders and rebuild your project.
The issue is most likely related to the fact that you are using anewer API level device/emulator and you are lacking the SDK version - try installing SDK 26 in your Android SDK manager and make clean rebuild (the step above)
I had the above issue, my emulator is running API25. I have installed through the SDK manager API's 25, 26, 27. I installed SDK Tools: Android SDK Build-Tools, Android SDK Platform-Tools, Android SDK Tools. (I also updated emulator/haxm/google play services) I have removed node_modules, hooks and platform folders and rebuilt my project (npm i, tns platform add android) I created a new emulator device running SDK 27 (This prompted me to download SDK27 even though I had it installed through SDK manager) I have also tried setting the target SDK in nativescript sidekick to 27
Running tns debug android
seems to be working fine. It is also now building in NativeScript Sidekick
Had the exact same issue as I was using the SDK-Version 25 for building my app. My build tools where v27.0.3 so I also installed the platform SDK for 27 by calling
sudo $ANDROID_HOME/tools/bin/sdkmanager "tools" "emulator" "platform-tools" "platforms;android-27" "build-tools;27.0.3" "extras;android;m2repository" "extras;google;m2repository"
and now it works!
this code does not work for me can you help me to solve the issue?
let session = bghttp.session('post');
let params = [];
const image = this.image;
console.log(image); //print as '/storage/emulated/0/DCIM/Camera/NSIMG_20181009_235736.jpg'
const param = {
name: "photos",
mimeType: 'image/jpeg',
fileName: image,
};
params.push(param);
const url = API_URL + '/posts';
let request = {
url: url,
method: 'POST',
headers: {
'Authorization': 'Bearer ' + this.authService.getToken(),
},
description:"Post Upload"
};
let task: bghttp.Task;
task = session.multipartUpload(params, request);
task.on('responded', this.onCompleteUpload);
task.on('error', this.onUploadError)
and I get this response
{
"eventName": "error",
"object": {
"_observers": {
"responded": [
{}
],
"error": [
{}
]
},
"_session": {
"_id": "post"
},
"_id": "post{3}",
"_description": "Post Upload",
"_upload": 153,
"_totalUpload": 153,
"_status": "error"
},
"error": null,
"responseCode": 400,
"response": {}
}
maybe image path is wrong?
@jenyaivanova521 I guess you are taking images with the device camera (or directly looking in the camera folder). In this case, you must save your image to an accessible folder. Then you could access the saved file and upload it.
Basic example:
import { File, Folder, path, knownFolders } from "tns-core-modules/file-system";
// to access the `android` native API use `tns-platform-declarations`
let androidDownloadsPath = android.os.Environment.getExternalStoragePublicDirectory(android.os.Environment.DIRECTORY_PICTURES).toString();
// instaed of accessing the DIRECTORY_PICTURES via native Android API, you could use the NativeScript knownFolders
// let downloadPath = knownFolders.documents();
myFolderPath = path.join(
androidDownloadsPath,
"MyFolderName"
);
let folder: Folder = Folder.fromPath(myFolderPath );
let myPath: string = path.join(myFolderPath , fileName);
let exists: boolean = File.exists(myPath);
if (!exists) {
let saved: boolean = imageSource.saveToFile(myPath, "jpg");
}
based on this logic.
Thank you for your advice can you attach sample accessible folder path? it is correct path?
/data/data/org.nativescript.nativescriptapp/files/app/NSIMG_20181011_102646.jpg
The Pictures folder is one example
let androidDownloadsPath = android.os.Environment.getExternalStoragePublicDirectory(android.os.Environment.DIRECTORY_PICTURES).toString();
or the documents folder which can be access directly via NativeScript
import { knownFolders } from "tns-core-modules/file-system";
let documentsFolder = knownFolders.documents();
By accessible I've meant a folder in which you would have write/delete access (so you could save your image taken from the camera for example). The path that you are showing is your application a path - you can read the image but you can't save or delete a file in any application folder.
I can't get this plugin to work.
I used this:
tns create sendFile-http-haz-ng3 --ng
and then installed this plugin:tns plugin add nativescript-background-http
I didn't change anything at all, and ran this:tns run android
andtns run ios
On iOS it runs OK, but on Android I get the error described below. Any ideas how to fix this please before I abandon NativeScript? Thanks