Hitesh
Hitesh

Reputation: 21

File upload using cordova app not working on remote server

I am trying to upload a file using my cordova app. The file was uploaded successfully when i was testing with localhost url. Now when i am trying with my remote server, it gives me the following error. It looks like its not even hitting the upload-url

FileTransferError {code: 1, source: "file:///storage/emulated/0/rec_13_13_11.wav", target: "https:///mobile_api/upload-hla-call-recording", http_status: 500, body: null, …}
body:null
code:1
exception:"https://route/to/upload/file"
http_status:500
source:"file:///storage/emulated/0/rec_13_13_11.wav"
target:"https://route/to/upload/file"

Here is the code for uploading file

fileSystem.root.getDirectory(dirName, {

                create: false

            }, function (dataDir) {

                fileURI = dataDir.toURL();

                fileURI = fileURI + fileName;

                var options = new FileUploadOptions();

                options.fileKey = "fileKey";

                options.fileName = fileURI.substr(fileURI.lastIndexOf('/') + 1);

                options.mimeType = "audio/mp3";

                options.chunkedMode = false;

                var ft = new FileTransfer();

                ft.upload(fileURI, server-url, win, fail, options, true);

            }, dirFail);

I am using cordova-plugin-file-transfer to upload the file

Upvotes: 2

Views: 375

Answers (1)

Hitesh
Hitesh

Reputation: 21

The issue was regarding the guzzlehttp. It was looking for https connection while my localhost was working on http. Either force the curl for http or provide a certificate with your http request.

Upvotes: 0

Related Questions