PutObject into directory Amazon s3 / PHP

前端 未结 3 969
没有蜡笔的小新
没有蜡笔的小新 2021-01-04 00:13

I need to upload my files inside specific directories that I created on my amazon s3 storage. I always uploaded the files on the \"absolute path\" of my bucket doing somethi

相关标签:
3条回答
  • 2021-01-04 00:45

    thank you Jeremy Lindblom, this is my python example that worked for me.

    import boto3
    s3 = boto3.resource('s3')
    data = open('/home/briansanchez/www/red-hat.jpg', 'rb')
    s3.Bucket('briansanchez').put_object(Key='www/red-hat.jpg', Body=data)
    
    0 讨论(0)
  • 2021-01-04 00:55

    Updated code according to the latest SDK of AWS:-

    $result = $s3->putObject(array(
        'Bucket' => 'bucket name of S3',
        'Key' => 'pawan-trying',
        'SourceFile' => 'local image path or document root image path ',
        'ContentType' => 'image',
        'ACL' => 'public-read',
        'StorageClass' => 'REDUCED_REDUNDANCY',
        'Metadata' => array(
            'param1' => 'value 1',
            'param2' => 'value 2'
        )
            ));
    
    0 讨论(0)
  • 2021-01-04 00:56

    You must include that information in the "Key" parameter. S3 isn't actually a filesystem, it's more like a big (hash table) associative array. The "Bucket" is the name of the hash table, and the "Key" is the key (e.g., $bucket[$key] = $content). So all path/directory information must be a part of the "Key".

    $localImage = '/Users/jim/Photos/summer-vacation/DP00342654.jpg';
    $s3->putObject(array(
        'Bucket'     => 'my-uniquely-named-bucket',
        'SourceFile' => $localImage,
        'Key'        => 'photos/summer/' . basename($localImage)
    ));
    
    0 讨论(0)
提交回复
热议问题