Transfer plugin doesn't work when app built with --prod key


#1

My application uses Camera plugin to take shots and Transfer plugin to upload photos.
When I build it with ionic build android it works just fine, though starts too slowly, up to 10 seconds.
When it was built with ionic build android --prod it starts much faster, but file uploading doesn’t work.
There is no errors, it looks like call to fileTransfer.upload(...) does nothing.
All other parts including camera still work.

Any suggestions how this can be fixed?


#2

I still have no solution for this problem.
I moved application to 3.1.0 framework version, tried building --release apk, but result is the same.
So any help will be highly appretiated.
Any ideas?


#3

Did you remote debug the problem on the device already?
Follow these instructions here to debug the problem in Safari dev tools: https://ionic.zone/debug/remote-debug-your-app#ios
Follow these instructions here to debug the problem in Chrome dev tools: https://ionic.zone/debug/remote-debug-your-app#android
Look at the console and network tabs for errors.


#4

Thank you for your response.
I tried to do remote debugging, but couldn’t see my application in list though it was launched on the phone.


I suppose it can be connected to optimizations that --prod key do.


#5

No, --release would be the culprit. Which build are you running right now?


#6

Thanks. You’re right, it was build with the --release key.
Now it available in DevTools, but I can’t see any errors there.
I have some “consolelogs” in code:

       console.log('Before image upload');
       this.uploadImage(filePath).then( imgResult => {
         console.log('After upload');
       ..... 
     private uploadImage(imagePath: string):Promise<any> {
       console.log('uploadImage start');
       let fileOptions: FileUploadOptions = { /* ... options definition here ...*/  };
       let serverUrl = /* ... url construction here ... */ ;
       console.log(fileOptions);
       console.log(serverUrl);
       return this.fileTransfer.upload(imagePath,
           serverUrl,
           fileOptions, true);
     }

And on invocation I have in console this:

Before image upload
uploadImage start
Object {fileKey: “file”, fileName: “1493806522446.jpg”, mimeType: “image/jpeg”, chunkedMode: true}
http://10.244.244.2:8080/AccountSystem/services/file

and no network activity, and "After upload" or any other logging that goes after call to fileTransfer.upload() never happens.


#7

The sample code from the docs on upload():

fileTransfer.upload(..).then(..).catch(..);

or

fileTransfer.upload('<file path>', '<api endpoint>', options)
   .then((data) => {
     // success
   }, (err) => {
     // error
   })

#8

In fact I do it this way:

 let fileTransferResult = fileTransfer.upload(..);
 fileTransferResult.then(..).catch(..);

and I was sure it’s the same as the quoted example.
It’s not?


#9

The catch is missing in the code you posted.
So does it catch? What is the error?

If you get no output, try the other way.


#10

Though catch isn’t shown in my code snippet it’s definitely there, and it doesn’t catch anything.
So I’ll try to do file upload literally as in your examples.


#11

Well, I’ve created a minimal example, and it again doesn’t work when being built with --prod key.
The complete code is here, can you take a look?


#12

Maybe you have to use it like that:

constructor(public navCtrl: NavController, private transfer: Transfer, private platform: Platform) {
  this.platform.ready().then(res => {
    this.fileTransfer = this.transfer.create();
  }
}

Then your code is executed after the native plugins are loaded.


#13

That’s it!
Thank you very much!