0
私はイオン3でアプリを開発しており、ルーメンフレームワークで作成されたAPIを使用してサーバーに画像をアップロードする必要があります。 画像のアップロード要求: 画像はカメラからクリックされ、base64に変換されます。アップロード画像ionic 3
let base64Image = 'data:image/jpeg;base64,' + imageData;
その後、私は画像
import { FileTransfer, FileUploadOptions, FileTransferObject } from '@ionic-native/file-transfer';
buildHeadersDeals(){
this.header = new Headers();
this.header.append('Authorization', 'Basic '
+btoa("test:test"));
}
uploadPhoto(image, token) {
this.buildHeadersDeals();
url = 'http://192.168.2.12/api/upload?token="+token;
const fileTransfer: FileTransferObject = this.transfer.create();
let options: FileUploadOptions = {
fileKey: 'photo',
fileName: image.substr(image.lastIndexOf('/')+1),
chunkedMode: true,
mimeType: "image/jpeg",
headers: this.header,
}
return fileTransfer.upload(image, encodeURI(url), options)
.then((data) => {
console.log(data);
return data;
}, (err) => {
console.log(err);
});
}
をアップロードするのFileUploadを使用して、私のAPIエンドがある:
public function upload(Request $request) {
if ($request->hasFile('photo')) {
$image = $request->file('photo');
$response['image'] = $image;
return response()->json($response,200);
}
}
私は2つの問題を抱えて:
1)私はいつものように写真を入手null($ request-> file( '写真'))
2)いくつかのいずれかが、以下のコードが動作しない、のparamsとしてトークンを送信するために教えてもらえます:私は「コルドバ・プラグインカメラ」をインストールしてい
let options: FileUploadOptions = {
fileKey: 'photo',
fileName: image.substr(image.lastIndexOf('/')+1),
chunkedMode: true,
mimeType: "image/jpeg",
headers: this.header,
params: {
'token': 'sffsdhnzchvh'
}
}
おかげ