link137 link138 link139 link140 link141 link142 link143 link144 link145 link146 link147 link148 link149 link150 link151 link152 link153 link154 link155 link156 link157 link158 link159 link160 link161 link162 link163 link164 link165 link166 link167 link168 link169 link170 link171 link172 link173 link174 link175 link176 link177 link178 link179 link180 link181 link182 link183 link184 link185 link186 link187 link188 link189 link190 link191 link192 link193 link194 link195 link196 link197 link198 link199 link200 link201 link202 link203 link204 link205 link206 link207 link208 link209 link210 link211 link212 link213 link214 link215 link216 link217 link218 link219 link220 link221 link222 link223 link224 link225 link226 link227 link228 link229 link230 link231 link232 link233 link234 link235 link236 link237 link238 link239 link240 link241 link242 link243 link244 link245 link246 link247 link248 link249 link250 link251 link252 link253 link254 link255 link256 link257 link258 link259 link260 link261 link262 link263 link264 link265 link266 link267 link268 link269 link270 link271 link272 link273

[Vue.js] Can't upload image only on mobile device Laravel + Vue

I read about this on some posts on the stack, but I still do not see the same case as mine. I can not upload the image on phone device. I do not see why I do not have a console to see error. I’ll show you the code, so someone who is experienced can see the error.

Laravel code to upload image:

public function uploadImage($car, $images)
{
$fileName = Carbon::now()->timestamp . $images->getClientOriginalName();
$path = $images->move(public_path(‘public/images’), $fileName);
if (!$path) {
return response()->json([‘message’ => ‘An error has accured’], 500);
}
$carImage = new CarImages ([
‘path’ => ‘public/images/‘ . $fileName
]);

$car->images()->save($carImage);
return $carImage;
}

Laravel code for store form with image:

public function store(CarRequest $request)
{
$file = null;
if ($request->has(‘picture’)) {
$file = $request->file(‘picture’);
}
$user = auth()->user();
if ($user) {
$car = Car::create([
‘car_type’ => $request->input(‘car_type’),
‘mark’ => $request->input(‘mark’),
‘model’ => $request->input(‘model’),
‘user_id’ => $user->id
]);
}
if (!$car) {
return response()->json([‘message’ => ‘Oooops, something went wrong’], 500);
}
if ($file) {
$carImage = $this->uploadImage($car, $file);
}
Mail::to($user->email)->send(new NotifyNewCarUpload($user, $car));
return response()->json([
‘message’ => ‘the car has been successfully added’,
‘car’ => $car,
‘user’ => $user
], 201);
}

In CarRequest for upload for car i have:

‘car_type’ => ‘required’,
‘mark’ => ‘required’,
‘model’ => ‘required’,
‘picture’ => ‘required|image’

In Vue.js insert car I have:

<form enctype=”multipart/form-data” accept-charset=”utf-8”
@submit.prevent=”submit”>


<div class=”col-3 insert-vehicle-right”>
<div :class=”{ ‘error’: errors.has(‘file’) }” v-if=”!imgSrc” class=”image-upload-holder”></div>
<img :class=”{ ‘error’: errors.has(‘file’) }” v-if=”imgSrc” class=”uploaded-image” :src=”imgSrc” alt=”uploaded image”/>
<div class=”upload-btn-wrapper”>
<button class=”btn action-btn”>Upload Photo</button>
<input name=”file”
v-validate=”‘required’”
type=”file”
@change=”onFileChange”/>
</div>
</div>
</div>
<div class=”row”>
<div class=”col-12”>
<button type=”submit” class=”btn action-btn save-btn”>Save</button>
</div>
</form>

Vue.js javascript code for upload and preview image code:

onFileChange(event) {
this.picture = event.target.files[0];
const file = event.target.files[0];
this.imgSrc = URL.createObjectURL(this.picture);
},

And there is formData code for post that code:



formdata.append(‘picture’, this.picture);

It’s not working on mobile phones. Does anyone recognize the reason?
All my pictures are stored in the laravela folder public/public/images and work good on web browser (destop and laptop device). Also there is table for storing path images.. Only for phone device not work. Help?

Solution :

Okey problem was be in php.ini configuraction and max_size_upload file. I only set more than 2mb images file and work perfecty.
@thanks Rasa