Lyrical.me
Lyrical.me

Reputation: 215

Upload limits on Heroku / Bucketeer (S3)

I am using Heroku and their S3 addon - "Bucketeer".

I have this working and I can upload images no problem. The thing is I don't care about uploading images. My app deals with uploading MP3s (nothing sinister - it's a web app for local bands).

I can't upload MP3s. It doesn't error out or anything, it's just that files don't end up in S3 - whereas images uploaded exactly the same way, do.

Editing to add - It's not a file type issue as I tested by uploading a very small mp3 file and this worked great.

Code below:

        <form class="form" action="../model/process-track-upload.php" method="post" enctype="multipart/form-data">
              <div class="row">
                <div class="col-xs-12 col-sm-4">
                  <div class="dashboard-widget">
                      <h3>Add a song to your collection</h3>
                      <input class="input" type="text" name="trackname" placeholder="Track Name" required/>
                      <input class="input-margin" name="userfile" type="file">
                      <input type="hidden" name="userID" value="<?php echo $userID ?>" />
                      <button class="btn btn-large btn-block " type="submit" name="btn-upload">upload</button>
                  </div>
                </div>
              </form>

And the backend code:

require('../vendor/autoload.php');

$s3 = Aws\S3\S3Client::factory();
$bucket = getenv('S3_BUCKET')?: die('No "S3_BUCKET" config var in found in env!');

if($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_FILES['userfile']) && $_FILES['userfile']['error'] == UPLOAD_ERR_OK && is_uploaded_file($_FILES['userfile']['tmp_name'])) {

    try {

        $upload = $s3->upload($bucket, $_FILES['userfile']['name'], fopen($_FILES['userfile']['tmp_name'], 'rb'), 'public-read');
?>
        <p>Upload <a href="<?=htmlspecialchars($upload->get('ObjectURL'))?>">successful</a> :)</p>
<?php } catch(Exception $e) { ?>
        <p>Upload error :(</p>
<?php } }

Upvotes: 1

Views: 604

Answers (1)

Lyrical.me
Lyrical.me

Reputation: 215

The answer to this question lay in default php settings.

HOWEVER as I was using Heroku, I didn't have access to the php.ini file.

So the answer was to create a .users.ini file which is like a user created override of the php.ini.

In that file I just set the following params:

upload_max_filesize = 15M
post_max_size = 15M
max_input_time = 0
LimitRequestBody 0

After this I was good to go!

Upvotes: 1

Related Questions