invalid according to policy policy condition failed starts-with $content-type ""

StackOverflow https://stackoverflow.com/questions/20525214

  •  31-08-2022
  •  | 
  •  

Question

I am trying to upload photo using fineuploader 3.8.2 on Sony Xperia Tipo or HTC Evo 3d with android 4.0 and facing a strange issue. While uploading through camera works, uploading through gallery is not working and giving me invalid according to policy policy condition failed starts-with $content-type "" error

$('#fineuploader-s3').fineUploaderS3({
        request: {
            endpoint: "http://mybucket.s3.amazonaws.com",
            accessKey: "MYACCESSKEY"
        },

        signature: {
            endpoint: "myendpoint",
        },

        objectProperties: {
            acl: 'public-read',
            key: =>
                uploaded_image_key = qq.getUniqueId()
                return "#{uploaded_image_key}.png"
        },

        iframeSupport: {
            localBlankPagePath: "/myiframe.html"
        },

        text: {
            uploadButton: '<div><i class="icon-upload"></i>&nbsp;Upload Image</div>'
        },

        uploadSuccess:{
            endpoint: null
        },

        template: 'mytemplate',

        camera: {
            ios: true
        },

        multiple: false,

        retry: {
            showButton: true
        },

        validation: {
            allowedExtensions: ["gif", "jpeg", "jpg", "png"],
            acceptFiles: "image/gif, image/jpeg, image/png"
        },

        chunking: {
            enabled: true
        },

        resume: {
            enabled: true
        }
    }).on('complete', (event, id, fileName, responseJSON) =>
            if responseJSON.success
                $(@el).find('#thumb_pics').append("<img class='thumb' src ='http://s3.amazonaws.com/mybucket/#{uploaded_image_key}.png' title = '#{fileName}' />")
                $('#submit_feedpost').prop('disabled', false)
        ).on('error', (event, id, fileName, errorReason, xhr) =>
            $('#submit_feedpost').prop('disabled', false)
                            alert(errorReason)
        )

My policy is like this -

'{
"expiration": "myexpirationdate",
"conditions":[
    {"bucket": "mybucket"},
    ["starts-with", "$key" , ""],
    {"acl": "public-read"},
    {"success_action_status": "200"}, 
    ["starts-with", "$Content-Type", ""],
    ["starts-with", "$x-amz-meta-qqfilename", ""]
    ]
}'

My CORS is like this -

<CORSRule>
    <AllowedOrigin>*</AllowedOrigin>
    <AllowedMethod>GET</AllowedMethod>
    <AllowedMethod>POST</AllowedMethod>
    <AllowedMethod>PUT</AllowedMethod>
    <AllowedHeader>*</AllowedHeader>
</CORSRule>
Était-ce utile?

La solution

Sorry to trouble you. I find out the issue. I was using my own policy to sign it rather than signing the policy sent in the post request to my endpoint by fineuploader library. Anyways thanks a lot

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top