Using PHP to connect to Azure blob storage account. Using azure-storage-php ( github )
For the copy i use BlobRestProxy.copyBlob() using the api.
I am able to connect to the azure blob storage. Able to upload, list, delete blob files. But not able to copy the blob file within the same container. Does anyone has an example of how to copy a blob file within php using azure-storage-php or does anyone recognizes the error?
I already tried it with several blob storage account settings (public and not). For authentication i use a Shared Access Signature. The weird thing is that i am able to do alle things like create, read and delete but copy does give the below error. Thanks in advance.
The storage account is new, created at 3-12-2021
Fail:
Code: 409
Value: Public access is not permitted on this storage account.
details (if any): <?xml version="1.0" encoding="utf-8"?><Error><Code>CannotVerifyCopySource</Code><Message>Public access is not permitted on this storage account.
RequestId:4b324b08-b01e-0009-6c1e-1187a1000000
Time:2022-01-24T12:30:35.8956602Z</Message></Error>.
Thanks for the reply allready!
The Shared Access Signature specified on the request applies only to the destination blob while using Copy Blob
Access to the source blob is authorized separately
If you are using the shared key (Storage Account Key), the authorization would have been done with the same key
As you are using Shared Access Signature, you need to append the SAS token in the x-ms-copy-source in the request
Thanks to RamaraoAdapa-MT, your answer was very helpfull. The developer has fixed the problem now.
And it was indeed the case that if you use the storage account key the copy is done with the same key. Public access is not necessery in both cases (SAS or AccountKey)
Related
I have a public S3 bucket called latheesan-public-bucket (for example) in AWS in the eu-west-1 region.
If I were to visit the following url in the browser (for example):
https://latheesan-public-bucket.s3-eu-west-1.amazonaws.com/
I get the following XML showing that I have one file in the bucket:
<?xml version="1.0" encoding="UTF-8"?>
<ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<Name>latheesan-public-bucket</Name>
<Prefix />
<Marker />
<MaxKeys>1000</MaxKeys>
<IsTruncated>false</IsTruncated>
<Contents>
<Key>test.json</Key>
<LastModified>2017-07-11T16:39:50.000Z</LastModified>
<ETag>"056f32ee5cf49404607e368bd8d3f2af"</ETag>
<Size>17658</Size>
<StorageClass>STANDARD</StorageClass>
</Contents>
</ListBucketResult>
If I were to then visit https://latheesan-public-bucket.s3-eu-west-1.amazonaws.com/test.json I can download my file from my public bucket.
In order to achieve the same in my Laravel application; I first added this package via composer:
league/flysystem-aws-s3-v3
Then on my .env I've added the following lines:
AWS_REGION=eu-west-1
AWS_BUCKET=latheesan-public-bucket
Lastly, I then tried to use the laravel filesystem to access the public s3 bucket file like this:
$json = Storage::disk('s3')->get('test.json');
When I did this; I got the following error:
Error retrieving credentials from the instance profile metadata
server. (cURL error 28: Connection timed out after 1000 milliseconds
(see http://curl.haxx.se/libcurl/c/libcurl-errors.html))
So, I updated my .env with some fake credentials:
AWS_KEY=123
AWS_SECRET=123
AWS_REGION=eu-west-1
AWS_BUCKET=latheesan-public-bucket
Now I get this error:
Illuminate \ Contracts \ Filesystem \ FileNotFoundException
test.json
So my question is; firstly what am I doing wrong here? Is there no way to access a public s3 bucket in laravel without actually providing a valid S3 Key/secret? what if I don't know them? I only have the url to the public s3 bucket.
P.S. the latheesan-public-bucket does not exist (it was a dummy bucket name to explain my problem, I do have a real public bucket I am trying to work with and it works fine in browser as explained above).
When you try to access it via the HTTPS URL, it works because it is public, and you're
When you try to access it via the SDK, it is trying to use the API to access it.
So either give your instance profile the correct permissions to access the bucket (which would no longer need to be public) or simply use an http client to retrieve the file.
If you use the S3 API to access your bucket, AWS credentials are required. The reasons is that the API needs to sign the S3 request.
I want that PHP/Drupal reads configuration settings which are stored in my CSCFG file and in my cloud service instance respectively.
How do I read configuration data (DB credentials) in a PHP web role in azure? I need them to access my database.
I have my DB credentials in two places
my azure account
(possibly) in my cscfg file
In my PHP script I want to get this data, so that my CSPKG files don't need to contain credentials. Example:
$db_host = azure_getconfig("DbHost");
$db_user = azure_getconfig("DbUser");
$db_password = azure_getconfig("DbPassword");
Is there a standard way how to do this?
About php_azure.dll: The approach that is usually described did not work for me. The suggested php extension php_azure.dll seems to be abandonded as it is marked as obsolete. I tried to load the extensions in all it's flavors but didn't succeed ("Unable to load dynamic library 'D:\Program Files (x86)\PHP\v5.3\ext\php_azure.dll' - The specified module could not be found.", even though the file exists for sure at the right path.).
So I assume, I shouldn't use php_azure.dll anyway.
There is a similar but unanswered question here:
How can I access ConfigurationSettings using a PHP Cloud Service on Windows Azure?
I'm trying to figure out how perform a browser direct upload to Amazon S3 using an XHR. I'm using some pre-made code that creates a signature and performs the upload. All I have to do is enter my S3 security credentials. (For what it's worth, I want to do the policy signing using PHP).
I've forked the code to my GitHub account, you can find it here: https://github.com/keonr/direct-browser-s3-upload-example
As the readme file indicates, I have set my S3 bucket CORS to allow all origins, as such:
<CORSConfiguration>
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>PUT</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<AllowedHeader>Content-Type</AllowedHeader>
<AllowedHeader>x-amz-acl</AllowedHeader>
<AllowedHeader>origin</AllowedHeader>
</CORSRule>
</CORSConfiguration>
Now, when I try to perform the file upload, the script returns with XHR Error and my browser's error console gives me a standard CORS error, saying that my Origin is now allowed for that XHR request. I've tried everything I can think of. I've chaned the * wildcard to the actual domain the request originates from to allowing the * wildcard to allowed headers. Nothing seems to work. It continues to produce that CORS error.
Can anyone help me get this off the ground and successfully complete a direct browser upload to S3? I don't care by which means, I just need to be able to get it done. Also, bear in mind that I am a novice when it comes to S3, so the more explicit the instructions, the better.
Thanks!
Try adding a wildcard for the AllowedHeader and allow all methods, like so:
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>PUT</AllowedMethod>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>
Great starting points for a direct upload to Amazon S3 are:
For the js:
http://www.designedbyaturtle.co.uk/2013/direct-upload-to-s3-with-a-little-help-from-jquery/
For the php:
http://birkoff.net/blog/post-files-directly-to-s3-with-php/
Or if you're looking for a solution that works out of the box, take a look at Plupload
Hope this gets you started!
I'm using the standalone PHP-S3 class:
http://undesigned.org.za/2007/10/22/amazon-s3-php-class
I've tried all the ready made tutorials, downloaded the source, changed the corresponding variables (set my bucket, access_key, access_secret).
I'm guetting the following error whenever I try to upload any file:
Warning: S3::putObject(): [417] Unexpected HTTP status in C:\Users\Jad\Dropbox\www\test\S3.php on line 312
Note: My bucket already exists and I even allowed all the permissions to the user everyone (temporarily for it to work but it's still not working)
I had the same problem.
If you are connected through a proxy in my case it worked connection to S3 over SSL.
$s3 = new S3(S3KEY, S3SECRET, true);
So I created a new bucket in the US (the last one was in Ireland) and everything works smoothly now.
I had the same problem. I'm connected to a proxy... If I'm connected to an other network, it works :)
I've had this issue behind a squid3 proxy and the problem was resolved by the following squid configuration directive:
ignore_expect_100 on
I am doing Push Notification Service for Apple iphone/ipad. i got the server side code from http://code.google.com/p/apns-php/. it is working well.. but i have to implement it in Yii framework.
i have googled it. and got this
https://github.com/shiki/yii-apns
Here i need to set server_certificates_bundle_sandbox.pem, and device token dynamically at run time.I am new to yii..please help me how to use this component..
i have extracted all the files in components folder,and tried the below code.
$obj=new SAPNS();
$obj->providerCertificateFilePath="provider certificate file path";
$obj->rootCertificationAuthorityFilePath="root certificate path";
$obj1=$obj->getPushProvider();
but while calling getPushProvider method,i got the following error.
include(ApnsPHP_Push.php): failed to open stream: No such file or directory
There is no such a file ApnsPHP_Push.php in ApnsPHP folder in my components folder.dont know in which part i did mistake..
the guys has already wrapped up everything in a component, so you just need to put all the things in components directory and call the desired functions.
if you look at SAPNS.php its got a public property
$providerCertificateFilePath
and that will be the file path to your PEM file and other
$rootCertificationAuthorityFilePath
for secure certificate (if any).
After giving these values you have to call getPushProvider method that will give you an object for ApnsPHP_Push from here you can call this class normally as you do without framework.