Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70432

IONIC v3 - FileTransfer - Upload don't send param for FileUploadOptions

$
0
0

@mgorosito wrote:

Hi everybody! I have a problem with plugin cordova-plugin-file-transfer when i try to send some params with file inside a request for a server.
In server only arrives the file with out extra params.

I tried with chunkedMode on true or false, with Connection header with value “close”, removing @ionic-native/transfer and installing @ionic-native/file-transfer but i have the same results. I don’t see what it is that wrong.

This is the method in my provider for upload Files:

import { AppConfig } from '../config';
import { Transfer, FileUploadOptions, TransferObject } from '@ionic-native/transfer';
import { HttpService } from '../http-service';
import { File } from '@ionic-native/file';
import { FilePath } from '@ionic-native/file-path';

let messagesURL = AppConfig.SERVER_URL + 'message';

@Injectable()
export class FileUploadServiceProvider {
  constructor(private transfer: Transfer, private file: File, private filePath: FilePath, public httpService: HttpService) {

  }

  uploadMessage(uri): Promise<string> {
    const fileTransfer: TransferObject = this.transfer.create();

    var headers = this.httpService.getOptions(messagesURL).headers;
    headers.set('Accept', 'application/json');
    headers.set('Content-Type', 'multipart/form-data');
    headers.set('Connection', 'close');

    let options: FileUploadOptions = {
      fileKey: 'file',
      fileName: 'file.' + uri.split('.').pop(),
      chunkedMode: false,
      headers: headers,
      params: {
        recipientId: 500
      }
    }

    fileTransfer.upload(uri, messagesURL, options)
      .then((data) => {
        return JSON.parse(data.response).filename;
      }, (err) => {
        console.log(err);
        return null;
      });

}

IONIC info:

Ionic:

   Ionic CLI          : 6.1.0 (/usr/lib/node_modules/@ionic/cli)
   Ionic Framework    : ionic-angular 3.4.2
   @ionic/app-scripts : 3.2.4

Cordova:

   Cordova CLI       : 8.1.2 (cordova-lib@8.1.1)
   Cordova Platforms : none
   Cordova Plugins   : cordova-plugin-ionic-keyboard 2.2.0, (and 31 other plugins)

Utility:

   cordova-res (update available: 0.12.2) : 0.9.0
   native-run (update available: 1.0.0)   : 0.3.0

System:

   Android SDK Tools : 26.1.1 (/usr/lib/android-sdk)
   NodeJS            : v12.16.2 (/usr/bin/node)
   npm               : 6.14.4
   OS                : Linux 5.3

The version of plugin-cordova-file-transfer is 1.7.1.

In any case the result is that the server does not receive the recipientId parameter.
Please any help will be useful to me.

Bye!

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 70432

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>