Click here to Skip to main content
16,004,727 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
var params = {
Bucket: 'Grade',

};

s3.listObjects(params, function (err, data) {

if (err) console.log(err);
else {
var textFiles = data.Contents.filter(function (file) {
return (file.Key.indexOf('.txt') > 0);
});

console.log(textFiles);
}
This Gives me list of objects from Amazon s3 Bucket.
The value returned here is an array i am not able to download the files from amazon..



how do i achieve my requirement?? ideas help would be appreciated..

What I have tried:

my html table to append data from json object
//var tr;
//for (var i = 0; i < Files.length; i++) {
// tr = $('');
// tr.append("" + Files[i].name+ "");
// tr.append("" + Files[i].date+ "");
// tr.append("" + Files[i].Size + "");
// tr.append("" + "");.. //here download
//
//}
Posted
Updated 12-Apr-17 4:59am
v2
Comments
Karthik_Mahalingam 11-Apr-17 8:15am    
why ajax? try getting the data from code behind directly and bind the data to the gridview/
Mahesh2223 11-Apr-17 8:22am    
But getting data using function is very easy so using ajax that data need to use in code behind..any other easy way to do it
Mahesh2223 11-Apr-17 8:28am    
can u tel me how to get it using c# ??
please??
Karthik_Mahalingam 11-Apr-17 9:54am    
show the code how you are getting data from amazon
Mahesh2223 11-Apr-17 10:14am    
var params = {
Bucket: 'Grade',

};

s3.listObjects(params, function (err, data) {

if (err) console.log(err);
else {
var textFiles = data.Contents.filter(function (file) {
return (file.Key.indexOf('.txt') > 0);
});

console.log(textFiles);
}

this returns me data

1 solution

try like this

<!DOCTYPE html>
<html ng-app="" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <script src="Scripts/jquery-1.8.2.js"></script>
    <script>
        function openfile(obj) {
            window.open = obj.innerText;

        }

        $(function () {

            var items = [{ User_Name: 'aa', Score: 23, team: 'aa team' },
           { User_Name: 'bb', Score: 33, team: 'bb team' },
       { User_Name: 'cc', Score: 43, team: 'cc team' }];

            var url = 'https://grade.s3.amazon.com/';
            var rows = [];
            for (var i = 0; i < items.length; i++) {
                var item = items[i];
                var cols = [];
                cols.push('<td>' + item.User_Name + '</td>')
                cols.push('<td>' + item.Score + '</td>')
                cols.push('<td>' + item.team + '</td>')
                cols.push('<td> <a href="#" onclick="openfile(this)" > ' + item.User_Name + '.txt  </a> </td>')
                rows.push('<tr>'+cols.join('')+'</tr>');
            }
            $('#tbl tbody').append(rows.join(''));

        }) 

    </script>


</head>
<body>
    <table id="tbl" border="1" cellpadding="0" cellspacing="0">
        <thead>
            <tr>
                <th>User Name</th>
                <th>Score</th>
                <th>Team </th>
                <th>Download</th>
            </tr>
        </thead>
        <tbody></tbody>
    </table>

</body>
</html>


Edit: for downloading file from amazon s3 bucket :
var url = s3.getSignedUrl('getObject',params);
 
Share this answer
 
v3
Comments
Mahesh2223 12-Apr-17 2:15am    
bro small issue with this i am getting the page url of my aspx page , i am not able to redirect to amazon i have kept alert box and checked.
Karthik_Mahalingam 12-Apr-17 2:32am    
not clear
Karthik_Mahalingam 12-Apr-17 2:40am    
function openfile(obj) {
var url = 'https://grade.s3.amazon.com/' + obj.innerText;
window.open = url;

alert(url) // gives me aspx page url.
}
Mahesh2223 12-Apr-17 2:49am    
not working bro, may be because of window.open its takng same aspx page url
Karthik_Mahalingam 12-Apr-17 2:53am    
what is the value in url?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900