apache / apache/cordova-plugin-file-transfer

Getting http-status="401", code = 3 when uploading file in iOS. In Android it works fine.

Open
#304 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
606
Forks
874
PR merge metrics
No merged PRs in 30d

Description

# Bug Report

## Problem
Getting http-status="401", code = 3 when uploading file in iOS.

### What is expected to happen?
It should submit the file to server as it is working in Android.

### What does actually happen?
It gives the error below when submitted in iOS.
FileTransferError {
body = "[]";
code = 3;
"http_status" = 401;
source = "file:///var/mobile/Containers/Data/Application/9A7C2CF0-6DF7-4878-B0A9-5DEE99047652/Documents/637584019181140096_question.png";
target = "https://acceptance-nl.castoredc.org/api/study/F43BFEEC-588F-4E8A-BC26-6A974B83D08B/record/000842/data-point/survey/85E4F1D1-6219-4CAC-A248-7AEE91023221/9C245F0C-5573-45BC-80EB-BF97D17F7F73";
}

## Information
const fileTransfer = this.fileTransfer.create();
const options: FileUploadOptions = {
fileKey: 'upload_file',
fileName: 'image.jpeg',
httpMethod: 'POST',
mimeType: 'image/jpeg',
headers: {
Accept: '*/*',
...(secure && { Authorization: `Bearer ${await this.storageSvc.get(STORAGE_TOKEN, true)}` }),
},
params: { ...params },
};
return fileTransfer.upload(filePath, `${this._apiRoot}api/${uri}`, options);

### Environment, Platform, Device
Ionic:

Ionic CLI : 6.14.1 (/Users/usama/.nvm/versions/node/v14.15.4/lib/node_modules/@ionic/cli)
Ionic Framework : @ionic/angular 5.5.4
@angular-devkit/build-angular : 0.901.14
@angular-devkit/schematics : 11.2.1
@angular/cli : 9.1.14
@ionic/angular-toolkit : 2.3.3

Cordova:

Cordova CLI : 10.0.0
Cordova Platforms : android 9.0.0, ios 6.2.0
Cordova Plugins : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 5.0.0, cordova-plugin-ionic 5.4.7, (and 16 other plugins)

Utility:

cordova-res : 0.15.3
native-run : 1.3.0

System:

Android SDK Tools : 26.1.1 (/Users/usama/Library/Android/sdk/)
ios-deploy : 1.11.4
ios-sim : 8.0.2
NodeJS : v14.15.4 (/Users/usama/.nvm/versions/node/v14.15.4/bin/node)
npm : 6.14.10
OS : macOS Big Sur
Xcode : Xcode 12.5 Build version 12E262

Contributor guide

Open the contributing guide

Research direction

Start at the shown FileTransferOptions and fileTransfer.upload call, then compare the iOS and Android upload implementations in the Cordova plugin. Reproduce the upload with the supplied Authorization header and inspect why iOS receives HTTP 401. Done means the same authenticated file upload succeeds on iOS without breaking Android behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, javascript, objective-c
Domain
mobile-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.