-
-
Save prakashsvmx/4f29ac6733b0899ff135a456a5d7385a to your computer and use it in GitHub Desktop.
Upload to play.minio.io:9000 from browser using minio-js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Minio SDK for JavaScript - Sample Application</title> | |
<script src="./dist/main/minio-browser.js"></script> | |
</head> | |
<body> | |
<div id="results"></div> | |
<input type="file" id="file-chooser" /> | |
<button id="upload-button">Upload to Minio</button> | |
<script type="text/javascript"> | |
var s3 = new Minio.Client({ | |
accessKey: 'Q3AM3UQ867SPQQA43P2F', | |
secretKey: 'zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG', | |
endPoint: 'play.minio.io', | |
secure: true, | |
port: 9000 | |
}); | |
var fileChooser = document.getElementById('file-chooser'); | |
var button = document.getElementById('upload-button'); | |
var results = document.getElementById('results'); | |
var reader = new FileReader(); | |
button.addEventListener('click', function () { | |
var file = fileChooser.files[0]; | |
if (file) { | |
results.innerHTML = ''; | |
// Object key will be facebook-USERID#/FILE_NAME | |
var objKey = 'myobjects' + '/' + file.name; | |
var params = { | |
Bucket: 'testbucket', | |
Key: objKey, | |
ContentType: file.type, | |
Body: file, | |
}; | |
reader.onloadend = function () { | |
s3.putObject('testbucket', objKey, reader.result, file.type, function(e) { | |
if (e) { | |
results.innerHTML = 'ERROR: ' + e; | |
} else { | |
s3.statObject('testbucket', objKey, function(e, stat) { | |
if (e) { | |
results.innerHTML = 'ERROR: ' + e; | |
} else { | |
results.innerHTML = objKey + ' Size:' + stat.size + ' ETag:' + stat.etag; | |
} | |
}); | |
} | |
}); | |
} | |
reader.readAsText(file); | |
} else { | |
results.innerHTML = 'Nothing to upload.'; | |
} | |
}, false); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment