Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wanting to move from AWS to B2 #29

Closed
circa-III opened this issue Mar 14, 2019 · 2 comments
Closed

Wanting to move from AWS to B2 #29

circa-III opened this issue Mar 14, 2019 · 2 comments

Comments

@circa-III
Copy link

circa-III commented Mar 14, 2019

I know this isn't technically an issue, but was wondering if anyone could help me out. I have a website that I made for listing files in a bucket and allowing them to be downloaded, from S3. I'm wanting to move to B2 to save some money and I'm glad a PHP SDK exists, but I'm not a professional web dev, so I'm struggling to understand how to utilize this. It looks similar to the AWS SDK, but integrating it in my web page looks to be different. Here is an example of my existing code:

<?php
return [
		's3' => [
			'bucket' => 'gba.circa.im',
			'prefix' => '',
			'version' => 'latest',
			'region' => 'us-east-2',
			'credentials' => array(
				'key' => 'xxx',
				'secret' => 'xxx'
				)
		]
	];
$objects = $s3->getIterator('ListObjects', [
		'Bucket' => $config['s3']['bucket']
	]);
?>
	<?php foreach($objects as $object): ?>

	<li class="block">
		<div class="img gba">&nbsp;</div>
		<a href="<?php echo $s3->getObjectUrl($config['s3']['bucket'], $object['Key']); ?>" class="gba">
		<?php  $link = str_replace('.gba', '', $object['Key']); echo $link; ?>
		</a>
	</li>

Particularly the anchor part. I need the file path for the download link, and then the file name as well. Any help? I know it's probably not a good place to ask, but figured I'd start at the source.

@mhetreramesh
Copy link
Member

You have to do something like:

use BackblazeB2\Client;
use BackblazeB2\Bucket;

$options = ['auth_timeout_seconds' => seconds];

$client = new Client('accountId', 'applicationKey', $options);

$fileList = $client->listFiles([
    'BucketId' => 'YOUR_BUCKET_ID'
]);

foreach($fileList as $file) {
    //your logic goes here
}

@mhetreramesh
Copy link
Member

Closing for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants