Amazon S3: Subdomain mapping with PHP SDK? - php

How do you make $s3->get_object_url() from PHP SDK return:
http://my-bucket.my-domain.com/example.txt
instead of
http://my-bucket.s3.amazonaws.com/example.txt

S3 doesn't know if a bucketname has a CNAME set up for it, so you'll have to do it yourself. A simple call to preg_replace should work fine.
$url = preg_replace('#^http://my-bucket\.s3\.amazonaws\.com/#Ui', 'http://my-bucket.my-domain.com/', $url);

Related

Automatic download of Azure ServiceTags via php

I need to download Azure Public ServiceTag JSON from a PHP script. Unfortunately manual steps are required for the download (AWS offers direct download of json file with their networks).
The download link is following: https://www.microsoft.com/en-us/download/confirmation.aspx?id=57064
Hopefully, some has an idea of how follow the download link..
Thanks in advance!
You could try the below Service Tags -list REST API End Point :
GET https://management.azure.com/subscriptions/{subscriptionId}/providers/Microsoft.Network/locations/{location}/serviceTags?api-version=2020-05-01
Suggestion of REST API, because you wanted to invoke from the PHP. You will have to pass the authorization header.
Other Programmatical Approach
Get-AzNetworkServiceTag Powershell Commandlet
$serviceTags = Get-AzNetworkServiceTag -Location eastus2
az network list-service-tags Azure CLI Commandlet
az network list-service-tags --location
[--subscription
]
if you can do this with proper api's like in #Satya V's answer, it's a much better solution than web scraping, but if you don't have access to use the apis (seems you need a subscriptionId, whatever that is, to use the api),
you can grab the download link with the XPath //a[contains(.,'click here to download manually')]
this seems to work:
<?php
$ch = curl_init();
curl_setopt_array($ch,array(
CURLOPT_URL=>"https://www.microsoft.com/en-us/download/confirmation.aspx?id=57064",
// setting CURLOPT_COOKIEFILE to emptystring enables the cookie engine.
CURLOPT_COOKIEFILE=>"",
CURLOPT_RETURNTRANSFER=>1,
));
$html=curl_exec($ch);
$domd=new DOMDocument();
#$domd->loadHTML($html);
$xp=new DOMXPath($domd);
$download_url = $xp->query("//a[contains(.,'click here to download manually')]")->item(0)->getAttribute("href");
//var_dump($download_url);
curl_setopt_array($ch,array(
CURLOPT_RETURNTRANSFER=>0,
CURLOPT_URL=>$download_url
));
curl_exec($ch);

Youtube Signature issue with some videos

When I'm trying to generate video download URL from localhost with PHP, it's working perfectly creating signature automatically with all videos. But when I'm shipping my code to server trying to generate download URL (for same video), it's not giving Signature with same video. Why it's happening? If the video can create signature on localhost why not on server? What actually is the wrong thing? I'm just kinda stuck.
$id = $_GET['id']; //The youtube video ID
parse_str(file_get_contents('http://www.youtube.com/get_video_info?video_id='.$id.'&sts=&asv=3&el=detailpage'),$info);
$streams = explode(',',$info['url_encoded_fmt_stream_map']);
parse_str($streams[0], $str);
echo $str['url'];

Pre-Sign CNAME URL with PostObjectV4 (PHP SDK)

I am trying to use the AWS PHP SDK to pre-sign V4 POST URLs and am hitting a major problem.
I have created a bucket called bucket1.chris.com. This has a CNAME to bucket1.chris.com.s3-eu-west-1.amazonaws.com.
When I create the S3Client I am passing http://bucket1.chris.com as the enpoint and bucket1.chris.com as the bucket name.
Once the URL is signed and I get the action from the formAttributes it is:
bucket1.chris.com.bucket1.chris.com
Looking at the generateUri function in PostObjectV4 I can see this line:
// Use virtual-style URLs
$uri = $uri->withHost($this->bucket . '.' . $uri->getHost());
Which is causing my problem.
If I don't pass an endpoint I get:
s3-eu-west-1.amazonaws.com/bucket1.chris.com
(This is throwing an error: "The specified method is not allowed against this resource" when I try to use it but I think this might be something else)
Does anyone know how I you are supposed to use CNAME records (virtual hosted buckets) with the AWS PHP SDK?
I have figured out what I was doing wrong.
I don't need to worry about passing an endpoint to the SDK since it is not used in the signing process.
The problem I was having with the s3-eu-west-1.amazonaws.zom/bucket1.chris.com was due to an issue with the bucket and not the endpoint I was using.

How to test rest api written in codeigniter using URL manually

How can I test my rest api via URL?
I copied code from https://github.com/alexmarton/RControl and it only have instruction for get method.
So far what I've tried are :
http://test/api/blog/delete/2?format=json&X-API-KEY=1234
http://test/api/delete/2?format=json&X-API-KEY=1234
You can use Postman to test your APIs with manual data.

specifying a 30s ACL not working with Cloudfront?

Using the PHP Amazon SDK I am successfully able to set a 30 second access for a URL using the following functin: get_object_url($bucket, $filename, $preauth = 0, $opt = null)
$s3->get_object_url($results['s3.bucket.name'], $results['s3.file.name'], '30 seconds');
Now, the issue with this is that it returns a fantastic URL:
"s3.url": "http://THECOOLEST.BUCKET.INTHEWORLD.EVER.s3.amazonaws.com/2011/04/18/image/png/8ba2d302-a441-45d4-8354-08e2b7e1a325.png?AWSAccessKeyId=XXXXXXXXXXXXXXXXX&Expires=1303162244&Signature=AWdUnHSaIBDmRcbwo2RFSUQaqBM%3D",
When I change the URL to the CNAME we use for cloudfront, the ACL doesn't work. Anyone know how to get_object_url with the CNAME configured?
Cloudfront and S3 are two different things.
You need to setup a CNAME for your S3 bucket. See the AWS docs for more info: http://docs.amazonwebservices.com/AmazonS3/latest/dev/index.html?VirtualHosting.html#VirtualHostingCustomURLs

Categories