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

  • 5,000
  • Tác giả: admin
  • Ngày đăng:
  • Lượt xem: 5
  • Tình trạng: Còn hàng

I'm having problems when I want đồ sộ upload an image đồ sộ my amazon s3 bucket.

I'm trying đồ sộ upload a jpg image with the size of 238 KB. I've put a try/catch in my code đồ sộ kiểm tra what the error was. I always get this error:

Your proposed upload is smaller than thở the minimum allowed size

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

Here's my code:

 '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 tệp tin 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 links.)
Has anyone had this before? Searching on the mạng internet didn't help mạ much.
Also searching đồ sộ 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 tệp tin and then upload it from there. But isn't there a way đồ sộ store it directly without saving it locally?