GithubHelp home page GithubHelp logo

Comments (3)

martinbean avatar martinbean commented on May 19, 2024

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.

jeremeamia avatar jeremeamia commented on May 19, 2024

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.

martinbean avatar martinbean commented on May 19, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.