Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Encountering Internal server error 500 while uploading images to S3

I am facing an issue while uploading images to S3.I am using S3 class and jqueryimageuploader plugin for the same. I have set up the basic application,and it worked well from my local machine.As I deployed it on beanstalk it started throwing the error.I have attached the console snapshot alongwith. I am adding my code for reference here.enter image description here This is the launching file index.html -

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>jQuery File Upload Example</title>
</head>
<body>
<input id="fileupload" type="file" name="files[]"   data-url="http://mydomain.elasticbeanstalk.com/server/php/index.php" multiple>
<script src="js/jquery.min.js"></script>
<script src="js/vendor/jquery.ui.widget.js"></script>
<script src="js/jquery.iframe-transport.js"></script>
<script src="js/jquery.fileupload.js"></script>
<script>
$(function () {
$('#fileupload').fileupload({
    dataType: 'json',
    done: function (e, data) {
        $.each(data.result.files, function (index, file) {
            $('<p/>').text(file.name).appendTo(document.body);
        });
    }
});
$('#fileupload').fileupload({
/* ... */
 progressall: function (e, data) {
    var progress = parseInt(data.loaded / data.total * 100, 10);
    $('#progress .bar').css(
        'width',
        progress + '%'
    );
  }
 });
});

</script>
<style>
.bar {
  height: 18px;
  background: green;
}

My index.php --> this is called on the file upload click

<?php
 error_reporting(E_ALL | E_STRICT);
 require('UploadHandler.php');
 $upload_handler = new UploadHandler();

?>

The uploadHandler.php file can be found here
I will add the portion modified by me for uploading to S3

$bucket = "my bucket nmae";
$s3 = new S3(awsAccessKey, awsSecretKey);
$response = $s3->putObjectFile($file_path,$bucket,$file->name,S3::ACL_PUBLIC_READ);
$thumbResponse = $s3->putObjectFile('files/thumbnail/'.$file->name,$bucket,'images  /'.$file->name,S3::ACL_PUBLIC_READ);
echo $response;
echo $thumbResponse;
if ($response==1) {
 echo 'HERER enter!!';
  } else {
      $file->error = "<strong>Something went wrong while uploading your    file... sorry.</strong>";
 }

I am not uploading too big files and it works fine on my local machine,but fails on beanstalk.Any help would be great.Thank you for the attention.

like image 638
KillABug Avatar asked Oct 03 '22 14:10

KillABug


1 Answers

A HTTP 500 error means you have something "wrong" in your application that needs fixing (ie: it's the developer's fault as opposed to the user's fault like a 404)

To find out exactly what the issue is (there could honestly be 1000s of reasons why a HTTP 500 is generated) you will need to look at your error log files. If it is using the standard LAMP stack you should be able to find this error log here: /var/log/apache2/error.log (but there could be many other locations)

My guess is that you have a file permissions issue. I'm guessing that the user doesn't have write access to the folder you're trying to upload the images to in which case you will need to make that folder writeable (in Linux simply type: sudo chmod -R a+rwX /make/this/folder/something/writeable). but again this is only a guess, you will need to double check your error log file first.

like image 106
John Crawford Avatar answered Oct 12 '22 11:10

John Crawford