Skip to content
This repository has been archived by the owner on Nov 19, 2018. It is now read-only.

File gets uploaded on s3 but signing failed in laravel controller #3

Open
pushpendraas400 opened this issue May 6, 2017 · 2 comments

Comments

@pushpendraas400
Copy link

pushpendraas400 commented May 6, 2017

Hi:
I am using fineuploader s3 server for laravel. I am using laravel 5.4. I have setup bucket, bucket policy, IAM User ,created group as suggested here:

https://blog.fineuploader.com/2013/08/16/fine-uploader-s3-upload-directly-to-amazon-s3-from-your-browser/

My bucket CORS settings look like:

<?xml version="1.0" encoding="UTF-8"?> <CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> <CORSRule> <AllowedOrigin>*</AllowedOrigin> <AllowedMethod>GET</AllowedMethod> <AllowedMethod>POST</AllowedMethod> <AllowedMethod>PUT</AllowedMethod> <AllowedMethod>DELETE</AllowedMethod> <MaxAgeSeconds>3000</MaxAgeSeconds> <ExposeHeader>ETag</ExposeHeader> <AllowedHeader>*</AllowedHeader> <AllowedHeader>x-amz-acl</AllowedHeader> <AllowedHeader>x-amz-meta-qqfilename</AllowedHeader> <AllowedHeader>x-amz-date</AllowedHeader> </CORSRule> </CORSConfiguration>

Created a custom policy with following content

{
"Version":"2012-10-17",
"Statement":[{
"Effect":"Allow",
"Action":"s3:",
"Resource":"arn:aws:s3:::mybucketname/
"
}]
}

created a group called uploads-client and added policy and user to it.

use following javascript code:
` <script>
// Some options to pass to the uploader are discussed on the next page
var uploader = new qq.s3.FineUploader({
element: document.getElementById("uploader"),
debug:true,

objectProperties:{
'region':'us-east-1',
'bucket':'eauditions'

        },
        request: {
    endpoint: "eauditions.s3.amazonaws.com",
    accessKey: "AKIAIOTXKYEFLX6URQ5A"
},
signature: {
    endpoint: "{{url('api/endpoint_aws')}}",
    version:4,
},
 uploadSuccess: {
    endpoint: "{{url('api/endpoint_aws')}}?success",
    
},
cors: {
            expected: true
        },
validation: {
    allowedExtensions: ["gif", "jpeg", "jpg", "png"],
    acceptFiles: "image/gif, image/jpeg, image/png",
    sizeLimit: 500000,
    itemLimit: 1
},
        callbacks: {
            onComplete: function(id, name, response) {
                var previewLink = qq(this.getItemByFileId(id)).getByClass('preview-link')[0];

                if (response.success) {
                    console.log(response);
                  //  previewLink.setAttribute("href", response.tempLink)
                }
            },

             onError: function(id, name, errorReason, xhrOrXdr) {
        alert(qq.format("Error on file number {} - {}.  Reason: {}", id, name, errorReason));
    }


        }



    });
</script>`

I have also set the environment variables in .env file as stated here:

AWS_CLIENT_SECRET_KEY=BMnDU5NgT3urcTt33jv9ZWEa5RokI39NUEX0BTXS
AWS_SERVER_PUBLIC_KEY=AKIAIOTXKYEFLX6URQ5A

S3_BUCKET_NAME=eauditions
S3_HOST_NAME=http://eauditions.s3.amazonaws.com
S3_MAX_FILE_SIZE=500000
S3_BUCKET_REGION=us-east-1

S3_BUCKET_VERSION=2012-10-17

The issue is file gets uploaded to my bucket by fineuploader but laravel controller returns this JSON
{success: true, policy: "bnVsbA==", signature: "/etttCMJObj4YiHpBn0ke78LBns="}
it does not contain bucket name and key name or file name that gets uploaded.
Am i doing something silly here?
One more question
What is AWS_SERVER_PRIVATE_KEY HERE
is this IAM user secret key or .pem file key
What is AWS_SERVER_PUBLIC_KEY here
is this IAM user access key or .cert file key

please help me. I have been stuck here for past 2 days

@n7best
Copy link
Member

n7best commented May 6, 2017

I think the JSON response you got is from the signature phase which gives the client permission to upload the file, then the client upload to s3 with your defined bucket and key as config, with successful upload msg from s3, then the uploader will send a verify msg to the controller. The controller then verifies the file and size.

@pushpendraas400
Copy link
Author

pushpendraas400 commented May 7, 2017

Thanks for the reply but it seems i am still not getting anywhere. I have also tried to use fineuploader s3 php package https://github.com/FineUploader/php-s3-server but same thing happens file gets uploaded to bucket and response only contains success (no filename and bucket name). I am developing my project on a localhost. Is this the issue. I have set buckets CORS to have <AllowedOrigin>*</AllowedOrigin> and
<AllowedHeader>*</AllowedHeader>. Can't figure out the issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants