Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Amazon S3 - Your proposed upload is smaller than the minimum allowed size

I'm having problems when I want to upload an image to my amazon s3 bucket.

I'm trying to upload a jpg image with the size of 238 KB. I've put a try/catch in my code to check what the error was. I always get this error:

Your proposed upload is smaller than the minimum allowed size

I've also tried this with images from 1MB and 2MB, same error ... .

Here's my code:

<?php

// Include the SDK using the Composer autoloader
require 'AWSSDKforPHP/aws.phar';

use Aws\S3\S3Client;
use Aws\Common\Enum\Size;

$bucket = 'mybucketname';
$keyname = 'images';
$filename = 'thelinktomyimage';

// Instantiate the S3 client with your AWS credentials and desired AWS region
$client = S3Client::factory(array(
    'key'    => 'key',
    'secret' => 'secretkey',
));


// Create a new multipart upload and get the upload ID.
$response = $client->createMultipartUpload(array(
    'Bucket' => $bucket,
    'Key'    => $keyname
));

$uploadId = $response['UploadId'];

// 3. Upload the file in parts.
$file = fopen($filename, 'r');
$parts = array();
$partNumber = 1;
while (!feof($file)) {
    $result = $client->uploadPart(array(
        'Bucket'     => $bucket,
        'Key'        => $keyname,
        'UploadId'   => $uploadId,
        'PartNumber' => $partNumber,
        'Body'       => fread($file, 5 * 1024 * 1024),
    ));
    $parts[] = array(
        'PartNumber' => $partNumber++,
        'ETag'       => $result['ETag'],
    );

}

// Complete multipart upload.
try{
    $result = $client->completeMultipartUpload(array(
        'Bucket'   => $bucket,
        'Key'      => $keyname,
        'UploadId' => $uploadId,
        'Parts'    => $parts,
    ));
    $url = $result['Location'];

    fclose($file);
}
catch(Exception $e){
    var_dump($e->getMessage());
}

(I've changed the bucket, keys and image link.)
Has anyone had this before? Searching on the internet didn't help me much.
Also searching to change the minimum upload size didn't provide much help.

UPDATE:
When I tried this with a local image (changed the filename), it worked! How can I make this work with an image that's online? Now I save it in my temp file and then upload it from there. But isn't there a way to store it directly without saving it locally?

like image 224
nielsv Avatar asked Oct 15 '13 08:10

nielsv


People also ask

What is the minimum file size that you can upload into S3?

The size of an object in S3 can be from a minimum of 0 bytes to a maximum of 5 terabytes, so, if you are looking to upload an object larger than 5 gigabytes, you need to use either multipart upload or split the file into logical chunks of up to 5GB and upload them manually as regular uploads.

What is the max file size that we can upload to S3?

You can upload any file type—images, backups, data, movies, etc. —into an S3 bucket. The maximum size of a file that you can upload by using the Amazon S3 console is 160 GB. To upload a file larger than 160 GB, use the AWS CLI, AWS SDK, or Amazon S3 REST API.

What is the minimum size of each part in multipart object upload except last part?

Each part must be at least 5 MB in size, except the last part.

What is the minimum size of each part in a multipart object upload?

Each part in a multipart upload must be between 5 MiB (5,242,880 bytes) and 5 GiB (5,368,709,120 bytes). The last part can be smaller than 5 MiB (5,242,880 bytes). In general, part sizes should be as large as possible. For example, use part sizes of 5 GiB for a 100 GiB object.


1 Answers

The minimal multipart upload size is 5Mb (1). You probably want to use a "normal" upload, not a multipart upload.

(1) http://docs.aws.amazon.com/AmazonS3/latest/API/mpUploadUploadPart.html

like image 132
Paul Avatar answered Sep 20 '22 06:09

Paul