Comments (3)
I’ve decided to use Uploadify to upload the file via Flash, but still having difficulties.
With the new PHP SDK, how do I pass custom fields as policy options to PostObject
? I have the following in my PHP script:
$bucket = (string) $container['misc_config']->images->amazon->bucket;
$options = array(
'acl' => CannedAcl::PUBLIC_READ,
'Content-Type' => 'audio/mpeg',
'key' => 'audio/a-test-podcast.mp3',
'success_action_redirect' => (string) $container['misc_config']->main->base_url . 'upload/success/',
'success_action_status' => 201,
//array('starts-with', '$key', 'audio/'),
//array('starts-with', '$folder', ''),
array('starts-with', '$Filename', ''),
//array('starts-with', '$
);
$postObject = new PostObject($container['amazon_s3'], $bucket, $options);
But I keep getting the following error in the XML response:
Invalid Policy: Invalid Condition: unknown operation 'array'.
If I remove array('starts-with', '$Filename', '')
from the above code snippet, then I get the following error message:
Invalid according to Policy: Extra input fields: filename
What’s the syntax for adding these additional fields to my policy?
EDIT: Found the solution, and I don’t even know how! In my $options
array, I now have:
$options = array(
'acl' => CannedAcl::PUBLIC_READ,
'Content-Type' => 'audio/mpeg',
'key' => 'audio/a-test-podcast.mp3',
'success_action_redirect' => (string) $container['misc_config']->main->base_url . 'upload/success/',
'success_action_status' => 201,
'filename' => '^'
);
Don’t ask my have I managed to arrive at this solution, since it’s not documented anywhere I don’t think!
Although I am now faced with yet another issue. When using a Flash-based uploaded, how can I actually redirect on successful upload? My JavaScript function to instantiate Uploadify looks like this:
$('#file_upload').uploadify({
'buttonClass': 'button',
'buttonText': 'Upload',
'formData': <?php echo json_encode($formInputs); ?>,
'fileObjName': 'file',
'fileTypeExts': '*.mp3',
'height': 36,
'multi': false,
'onUploadError': function(file, errorCode, errorMsg, errorString) {
console.log('onUploadError', file, errorCode, errorMsg, errorString);
},
'onUploadSuccess': function(file, data, response) {
console.log('onUploadSuccess', file, data, response);
},
'swf': '/assets/site/swf/uploadify.swf',
'uploader': '<?php echo $uploadPath; ?>',
'width': 120
});
The content of my success page is logged in the console as the data
argument, but I’d like to actually redirect to that page, rather than having the response available to me in JavaScript. Is this an issue with Flash, JavaScript, Uploadify, what?
Finally, how can I enforce that only files with an .mp3 extension are uploaded?
from aws-sdk-php.
Seems like the file extension is enforced through the uploadify option fileTypeExts
. This will not be 100% accurate since it is just looking at the filename and not the mime. I would do some sort of validation on the object after it has been written to S3 and before you use it.
You should probably do the URL redirecting in the javascript layer (instead of php) in the onUploadSuccess
callback with window.location
perhaps.
It looks like you're making good progress on this though. Sounds like an interesting blog post once you have it all ironed out.
from aws-sdk-php.
Hi @jeremeamia. Yeah, I feel as though I’m making good progress with it. I’m going to close this as I seem to be pretty much there.
Also, I was planning on writing a blog post detailing how I used the PHP SDK to get uploads working 😉
Happy Thanksgiving! Thanks again, Jeremy.
from aws-sdk-php.
Related Issues (20)
- Add custom headers support to SES sendBulkTemplatedEmail HOT 6
- AwsS3S3Client::AwsS3{closure}(): Argument #1 ($e) must be of type AwsExceptionAwsException HOT 4
- no longer possible to use ElasticMQ since 3.286.2 HOT 3
- Unable to override IMDSv2 service URL HOT 3
- Use of SSO roles for PHP CLI HOT 1
- Incorrect argument type HOT 5
- fprintf(): supplied resource is not a valid stream resource HOT 4
- SignatureV4 mismatch on some requests HOT 7
- Deprecated: Using ${var} in strings is deprecated HOT 3
- Support 'OriginationNumber' when sending SMS. HOT 1
- Exception thrown in synchronous call "bleeds over" to asynchronous call HOT 3
- IRSA for Kubernetes not working HOT 3
- Argument 4 passed to Aws\Exception\AwsException::__construct() must be an instance of Exception or null HOT 3
- verifyDomainDkim method of SES Client returns validation error HOT 4
- Yum package
- InstanceProfile credentials provider causing open_basedir restriction error since 3.297.0 HOT 2
- Aws SQS: VisibilityTimeout value is zero and type is string instead integer HOT 5
- What version should I specify for MediaPackage and MediaPackageVod client? HOT 3
- PostObjectV4 with Custom Domain HOT 5
- File paths are not safe for Windows HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aws-sdk-php.