It's possible to store json on amazon s3?

前端 未结 3 1446
天涯浪人
天涯浪人 2021-02-19 07:33

I would like to store json file to my amazon s3 and then retrieve it with ajax request. Unfortunately it seems s3 does not allow content-type application/json....

I shou

3条回答
  •  庸人自扰
    2021-02-19 07:43

    I have found the problem. I was parsing the json in the wrong way.

    $.ajax({
        url:"https://s3.amazonaws.com/myBucket/myfile.json",
        type:"GET",
        success:function(data) {
                console.log(data.property)
        }
    })
    

    Instead this works:

    $.ajax({
        url:"https://s3.amazonaws.com/myBucket/myfile.json",
        type:"GET",
        success:function(data) {
            var obj = jQuery.parseJSON(data);
            if(typeof obj =='object'){
                console.log(obj.property)
            }
        }
    })
    

提交回复
热议问题