I have an ajax call that will upload a file to a Laravel app deployed at Heroku. This works flawless on my local environment.
On Heroku it will upload the file (I tried returning $logoImage in the ajax response and there is a tmp/whatever123 there) but when it's supposed to do the move, nothing happens. No file is put in the /public/img/local_logos folder. Also tried with only 'img/local_logos/' as path, which also works locally.
Could it be a https problem. I'm using https on Heroku. But then it should explode already when trying to upload the file. Sending normal forms with similar code works with no problems also in production.
Here's the function called by the ajax call.
public function postLocalLogo(Request $request)
{
if ($request->hasFile('logoImage')) {
$logoImage = $request->file('logoImage');
$path = base_path() . '/public/img/local_logos/';
$extension = $logoImage->getClientOriginalExtension();
$fileName = md5($logoImage->getClientOriginalName() . microtime()) . '.' . strtolower($extension);
$logoImage->move($path, $fileName); // This seems to not happen on Heroku
$storageLogo = new StorageLogo();
$storageLogo->filename = $fileName;
$storageLogo->save();
echo json_encode($fileName);
}
}
and here's the ajax function:
function uploadLogo() {
deleteLogoFromServer();
var logoFile = $('#logoImage')[0].files[0];
var data = new FormData();
data.append('logoImage', logoFile);
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
}
});
jQuery.ajax({
url: '/postajax',
data: data,
cache: false,
contentType: false,
processData: false,
method: 'POST',
success: function (data) {
localStorage.setItem('logoFileName', data);
$("#js-dataLocalLogo").val(localStorage.getItem('logoFileName'));
},
error: function (error) {
alert(error);
}
});
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire