本地化.错误:使用文件传输插件将文件从离子上传到 laravel 时未定义路由 [登录]



我正在使用 Rest api 将文件从离子上传到 laravel,首先我在 laravel 中准备 api 和控制器中的函数它在 laravel 中工作正常,其次在 ionic 应用程序中我正在使用文件、文件路径、文件传输,如您在下面的代码中看到的那样。 但是当我测试时,我得到了本地的。错误:未定义路由 [登录名] 在拉拉维尔.log。 这是我在拉拉维尔控制器中的代码

public function complaintsfile(Request $request){
$reclamation = Reclamation::latest('updated_at')->first();
$file = new Filee;
if(!$request->hasFile('file')){
return response()->json([
"action"=>"File empty"
]);
}
else{
$this->validate($request,[
'file' => 'required|mimes:doc,png,jpg,docx,txt,pdf|max:2048'
]);
$extention = time().'.'.$request->file->getClientOriginalExtension();
$fileName ="complain".'.'.$extention;
$request->file->move(public_path('upload'), $fileName);
$file->file= $fileName;
$file->rec_id=$reclamation->id;
$file->save();
}
}

还有这个我在离子中的代码

export class FillPage {
myRec = {
type:'' ,
project:'' ,
description:'',

}
myFile={
file:''
}
mood:any;
project:any;
uploadText:any;
downloadText:any;
fileTransfer:FileTransferObject;
constructor(public navCtrl: NavController, public navParams: NavParams,public complaint: ComplaintProvider
,public transfer:FileTransfer,public file:File,public filePath:FilePath,public fileChooser:FileChooser) {
this.complaint.Type().then((data)=>{
//   console.log(JSON.stringify(data))
this.mood=data["type"];
})
this.complaint.Project().then((data)=>{
//   console.log(JSON.stringify(data))
this.project=data["projects"];
})
this.uploadText="";
this.downloadText="";
}

uploadFile(){
this.fileChooser.open().then((uri)=>{
this.filePath.resolveNativePath(uri).then((nativepath)=>{
this.fileTransfer =this.transfer.create();
let options:FileUploadOptions={
fileKey:"pdf",
fileName:"file.pdf",
chunkedMode:false,
headers:{},
mimeType:'pdf'
}
this.uploadText ="uploading .....";
this.fileTransfer.upload(nativepath,'http://192.168.1.14:8000/api/complainfile',options).then((data)=>{
alert("transfer done="+JSON.stringify(data));
this.uploadText="";

},(err)=>{
this.uploadText=""
})
},(err)=>{
alert(JSON.stringify(err))
})
},(err)=>{
alert(JSON.stringify(err));
})
}
AbortUplaod(){
this.fileTransfer.abort();
alert("upload cancel.");
}

接口.php

<?php
use IlluminateHttpRequest;
/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/
Route::group([
//  'middleware' => 'api',
// 'namespace' => 'AppHttpControllers',
'prefix' => 'auth'
], function ($router) {
Route::post('login', 'APIAuthenController@login');
Route::post('logout', 'APIAuthenController@logout');
Route::post('refresh', 'AuthenController@refresh');
Route::post('me', 'AuthenController@me');
Route::get('/me','APIAuthenController@me');
});  
Route::get('/notif','APIProjetController@notifications');
Route::get('/notification','APIProjetController@notif');
Route::get('/me','APIAuthenController@guard');
Route::post('/login','APIAuthenController@login');
Route::post('/userauth','APIAuthenController@userauth');
Route::post('/markAsRead','APIProjetController@MarkUnread') ;  

Route::apiResource('client' ,'APIUserController@dashbord');
Route::get('membrep','APIUserController@Membreprojet');
Route::get('/chef', 'APIUserController@chef');
Route::post('/ajouterChefDeProjet','APIUserController@ajouterChefDeProjet');
Route::post('user-login' ,'APIUserController@login');
Route::apiResource('membre','APIUserController');
Route::post('updateuserconnecte','APIUserController@updateuserconnecté');
Route::get('/chef','APIUserController@chefprojet');
Route::get('/chefwP','APIUserController@chefprojetwP');
Route::get('userprofile/{id}','APIUserController@userprofile');
//UserProjet
Route::apiResource('/userprojet' ,'APIUserProjetController');
Route::get('/membreid/{id}','APIUserProjetController@show');
Route::get('/projetsuser','APIUserProjetController@projetuser');
Route::post('/chefdeprojet','APIUserProjetController@storeChef');
Route::post('/chefdeprojetparchef','APIUserProjetController@storeChefparchef');
//Client
//Route::post('/api/clientpname','APIUserController@updatename');
Route::get('nameprojet' ,'APIUserController@nomdeprojet');
Route::get('clientp','APIUserController@clientprojet');
Route::post('/ajouterClient','APIUserController@ajouterClient');
Route::get('/afficheclient', 'APIUserController@client');
//Projet
Route::get('/getProjects', 'APIProjetController@getProjects');
Route::apiResource('projet' ,'APIProjetController');
Route::post('/role' ,'APIProjetController@role');
Route::get('/role','APIProjetController@getrole');
Route::get('/projetadmin','APIProjetController@adminp');
Route::get('/getProjectsUserConnecte', 'APIProjetController@getProjectsUserConnecte');
//Commentaire
Route::post('/comments/{key}', 'APICommentController@store');
Route::get('/comments', 'APICommentController@show');
Route::post('/commentsreponse/{key}', 'APICommentController@storereply');
Route::post('/commentsreponset/{key}', 'APICommentController@storereplyt');
Route::get('/commentreply', 'APICommentController@showreply');
Route::post('/commentst/{key}', 'APICommentController@storet');
Route::get('/commentst', 'APICommentController@showt');
//calendar
Route::apiResource('/calendar', 'APICalenderController');
//gantt
Route::resource('/task', 'APITaskController');
Route::post('/task/{key}','APITaskController@store');
Route::put('task/{id}','APITaskController@update');
Route::delete('task/{id}','APITaskController@destroy');
Route::post('link','APILinkController@store');
Route::put('link/{id}','APILinkController@update');
Route::delete('link/{id}','APILinkController@destroy');
//Route::re}source('link', 'APILinkController');
Route::get('/tasks','APITaskController@getTask');
Route::get('/tasksdetail','APITaskController@getTaskt');
//Task
Route::post('/taskassign/{id}/{membre}','APITaskController@assign');
Route::get('/userTask','APITaskController@user');
Route::get('/hasparent','APITaskController@hasparent');
Route::get('membret/{id}','APIUserProjetController@showt');
Route::get('warn','APITaskController@warning');
Route::get('membretask','APITaskController@showmembre');
//reclamation
Route::resource('reclamation','APIReclamationController');
Route::get('/complain','APIReclamationController@complaints');
Route::post('/complainfile','APIReclamationController@complaintsfile');
Route::post('/complainfileionic','APIReclamationController@complaintsfileionic'); 
Route::get('/filesComplain/{id}','APIFileController@complaintsfile');
Route::get('/projetRec','APIReclamationController@projets');
Route::post('/reclamationassign/{id}/{membre}','APIReclamationController@assign');
Route::post('/type' ,'APIReclamationController@type');
Route::get('/type','APIReclamationController@gettype');
Route::post('/reclamationTerm/{id}','APIReclamationController@terminerReclamation');
Route::post('/reclamationAlert/{id}','APIReclamationController@alertReclamation');
Route::get('/reclamationmobile','APIReclamationController@reclamationmobile');
//profil
Route::put('profile', 'APIUserController@updateProfile');
Route::get('membrechef','APIUserController@Membrechefprojet');
//File
Route::get('/file/{id}','APIFileController@files');
Route::post('formSubmit/{id}','APIFileController@formSubmit');
Route::get('/filet/{id}','APIFileController@filest');
Route::post('formSubmitt/{id}','APIFileController@formSubmitt');
Route::post('formSubmitR','APIFileController@formSubmitR');
//stata
Route::get('/Nprojects','APIStatController@Nprojects');
Route::get('/Nclients','APIStatController@Nclients');
Route::get('/Nusers','APIStatController@Nusers');
Route::get('/Nleaders','APIStatController@Nleaders');
Route::get('/stats','APIStatController@stats');
Route::get('/Uprojects','APIStatController@Uprojects');
Route::get('/Ustats','APIStatController@Ustats');
Route::get('/Utasks','APIStatController@Utasks');
Route::get('/Cprojets','APIStatController@Cprojets');
Route::get('/Cprojet','APIStatController@projetsclient');
Route::get('/Ucomplaint','APIStatController@complaints'); 
Route::get('/Nprojectsc','APIStatController@NprojectsC');
Route::get('/NcomplaintsC','APIStatController@NcomplaintsC');
//});
Route::get('/data/{id}', 'APIGanttController@get');
Route::get('/data', 'GanttController@get');
Route::get('/verifcomplaint' ,'APIReclamationController@verifcomplaint');

请有人知道这个问题!

我想这可能是因为您没有授权 您需要在标志性的Bearer {token}中添加标头请求 并添加Accept: application/json

最新更新