Wired behavior of nativescript-background-http

android

#1

wired behavior of nativescript-background-http.
I wish to select, crop image from device and upload them to server. Since nativescript-background-http does not support uploading ImageSource object directly. I have to save it to file system.

But, sometimes nativescript-background-http cannot upload my file (it works on emulator but not on real device.)

request data:

filename is generated by: fs.path.join(fs.knownFolders.documents().path, fileName), fs is file system module

[{
JS:   "name": "x:purpose",
JS:   "value": "user_meta"
JS: }, {
JS:   "name": "x:uuid",
JS:   "value": "be2ce3f3-8c7a-426a-a2f8-75738ed761a4"
JS: }, {
JS:   "name": "file",
JS:   "filename": "/data/user/0/com.island68.MapleAndroid/files/Gs71xeEZl3VHvXlNcyb7.jpeg",
JS:   "mimeType": "image/jpeg"
JS: }]

the error mesasge:

{
JS:   "eventName": "error",
JS:   "object": {
JS:     "_observers": {
JS:       "error": [
JS:         {}
JS:       ],
JS:       "progress": [
JS:         {}
JS:       ],
JS:       "responded": [
JS:         {}
JS:       ],
JS:       "complete": [
JS:         {}
JS:       ]
JS:     },
JS:     "_session": {
JS:       "_id": "images-upload"
JS:     },
JS:     "_id": "images-upload{1}",
JS:     "_upload": 133,
JS:     "_totalUpload": 505403,
JS:     "_status": "error"
JS:   },
JS:   "error": {},
JS:   "responseCode": -1,
JS:   "response": null
JS: }

By using chrome debug tool, I found out that request never send out and I can visit the requested URL on browser.


#2

Have you acquired permissions to read / write documents directory (external storage read / write)?

Did you make sure whether the file really exists before sending it to plugin?


#3

I do have following on my xml file

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

But I’ll re check if I actually request the permissions


#4

Declaring permissions on just manifest will not allow you to write / read files in Android 6.x and above, you should acquire the permissions at run time.


#5

I confirm it is problem due to permissions, thanks for help!