Reputation: 11
I've been trying to send file with other post data which is mentioned in picture below also whenever i execute it, i only receive file but not other post data, it says "null" :-
Do i have to use multipart/form-data for file and other details for application/x-www-form-urlencoded ?
In my laravel project , api is set to POST
http://localhost/myproject/api/response
Route::post('response',function(Request $r){
$url = '';
if($r->hasFile('file')){
$file = $r->file('file');
$filename = time().$file->getClientOriginalName();
$path = public_path().'/uploads/videos/';
if(!empty($file->move($path, $filename)))
{
$url = asset('/uploads/videos/'.$filename);
}else {
$url = '';
}
}else {
$url = '';
}
$query = Table::create([
'response_status' => $r->get('status'),
'response_video_url' => $url,
'v_id' => $r->get('vid'),
'b_id' => $r->get('bid')
])->id;
if($query){
$data = [
'message' => 'Response is incorrect'
];
}else{
$data = [
'message' => 'Response received.',
'response_id' => $query,
'response_video_url' => $url
];
}
return response()->json($data);
});
Upvotes: 0
Views: 2216
Reputation: 11
I tried and i got the answer, there is no need to mention "application/x-www-form-urlencoded" while uploading file with data "multipart/form-data" is enough to do the job, by clicking on ADD TEXT PART and leave the Content Type (optional) field empty..
Thank you so much for help.
Upvotes: 1