How do I create a public link for a file in Object Storage?
I'd like to create a public link to a file in Object Storage so it can be downloaded using a tool like wget
. How can I do that?
8 Replies
I've looked into this, and while I wasn't able to find a way to do this from within the Cloud Manager, I did find a way to do it. You can use the s3cmd
tool create a public link in Object Storage. Here's how you do it:
First, you need to upload the file with the following command:
s3cmd put --acl public --guess-mime-type <test_file> s3://test_bucket/test_file
Or make an existing file public with:
s3cmd setacl --acl-public --guess-mime-type s3://test_bucket/test_file
Then, you should be able to download the file using wget
without any issue:
wget http://us-east-1.linodeobjects.com/test_bucket/test_file
How can we do this with the API? I'm wanting to do it from PHP and would prefer to not have to exec another program just to change the ACL.
Amazon have an official PHP SDK that works just fine with Linode’s Object Storage.
You can upload a file as public with the “public-read” ACL and then retrieve it’s URL.
This page has some samples for uploading.
To connect to Linode OS instead of S3, you pass “‘endpoint’ => ‘https://eu-central-1.linodeobjects.com’” in the SDK constructor (replace eu-central-1 with your cluster name).
To set an ACL, just pass “‘ACL’ => ‘public-read’” in the PutObject call.
Thank you, andysh. I see your hand in numerous forum posts regarding Object Storage and I appreciate it.
I see your hand in numerous forum posts regarding Object Storage because I still can't get it working.
Here's what I've done..
Installed amazon's SDK via composer..
This is the code I'm using…
$your_access_key = 'DAFaboutthislong8K';
$your_secret_key = 'this4one4is1much9longer74ak3f8Ksc53def0738aboutthislong342ee8Fk311';
$your_bucket_region = 'us-east-1'; // or 'eu-central-1'
$your_bucket_region = 'default'; // or 'eu-central-1'
$your_bucket_name = 'mymediabucket';
$auth_url = 'https://us-east-1.linodeobjects.com'; // or 'https://eu-central-1.linodeobjects.com'
$config = [
'credentials' => new \Aws\Credentials\Credentials(
$your_access_key,
$your_secret_key
),
'version' => 'latest',
'region' => $your_bucket_region,
'http_continue_timeout' => '0',
];
if (!empty($auth_url) && parse_url($auth_url) !== false)
{
$config['endpoint'] = $auth_url;
}
$s3Client = new \Aws\S3\S3Client($config);
$params = array(
'Bucket' => $your_bucket_name,
'Key' => 'my-file-name',
'Body' => 'this is the body!',
);
$result = $s3Client->putObject( $params);
print_r($result);
and it results in error:
Error executing "PutObject" on "https://mymediabucket.us-east-1.linodeobjects.com/my-file-name"; AWS HTTP error: Client error: `PUT https://mymediabucket.us-east-1.linodeobjects.com/my-file-name` resulted in a `403 Forbidden` response:
<?xml version="1.0" encoding="UTF-8"?><Error><Code>SignatureDoesNotMatch</Code><RequestId>tx000000000000002673c03-005f02 (truncated...)
SignatureDoesNotMatch (client): - <?xml version="1.0" encoding="UTF-8"?><Error><Code>SignatureDoesNotMatch</Code><RequestId>tx000000000000002673c03-005f023601-145c2e9-default</RequestId><HostId>145c2e9-default-default</HostId></Error>
The same keys work using the LinodeObjectStorage class (I had run across it via some forum post)
$apikey = 'this4one4is1much9longer74ak3f8Ksc53def0738aboutthislong342ee8Fk311';
$accesskey = 'DAFaboutthislong8K';
$los = new \Linode\ObjectStorage(
$apikey,
$accesskey,
false
);
$response = $los->put(
$object_path = 'ostest.php',
$cluster = 'us-east-1',
$bucket = 'mymediabucket'
);
print_r($response);
Any thoughts?
OK. I figured it out.
LinodeObjectStorage wants the apikey to be an API Token - Personal Access Token.
AWS-S3 expects the secret key to be the secret key that you are given when you create the Object Storage.
Hopefully this might help others in the same boat I've been in.
(And, the ACL public-read part works, too)
Thanks.
Glad you got it sorted.
LinodeObjectStorage wants the apikey to be an API Token - Personal Access Token.
This looks to be using the Linode API, so yes this would be a Linode API key.
AWS-S3 expects the secret key to be the secret key that you are given when you create the Object Storage.
The official AWS S3 SDK uses access keys and secrets, it doesn’t go through the Linode API. You can get a key and secret from the Object Storage > Access Keys page in Manager.
This error is coming when using Linode
Uncaught Error: Class 'Linode\ObjectStorage' not found
@qlapp --
@kvandivo writes:
The same keys work using the LinodeObjectStorage class (I had run across it via some forum post)
Did you install the same LinodeObjectStorage class into your project (presumably from the same forum post @kvandivo used)? If not, the class is undefined…hence the error.
-- sw