JavaScript in the Browser
<!DOCTYPE html>
<html>
<head>
<title>AWS SDK for JavaScript - Sample Application</title>
<script src="https://sdk.amazonaws.com/js/aws-sdk-2.1.12.min.js"></script>
</head>
<body>
<input type="file" id="file-chooser" />
<button id="upload-button" style="display:none">Upload to S3</button>
<div id="results"></div>
<div id="fb-root"></div>
<script type="text/javascript">
var appId = 'YOUR_APP_ID';
var roleArn = 'YOUR_ROLE_ARN';
var bucketName = 'YOUR_BUCKET_NAME';
AWS.config.region = 'YOUR_BUCKET_REGION';
var fbUserId;
var bucket = new AWS.S3({
params: {
Bucket: bucketName
}
});
var fileChooser = document.getElementById('file-chooser');
var button = document.getElementById('upload-button');
var results = document.getElementById('results');
button.addEventListener('click', function () {
var file = fileChooser.files[0];
if (file) {
results.innerHTML = '';
//Object key will be facebook-USERID#/FILE_NAME
var objKey = 'facebook-' + fbUserId + '/' + file.name;
var params = {
Key: objKey,
ContentType: file.type,
Body: file,
ACL: 'public-read'
};
bucket.putObject(params, function (err, data) {
if (err) {
results.innerHTML = 'ERROR: ' + err;
} else {
listObjs();
}
});
} else {
results.innerHTML = 'Nothing to upload.';
}
}, false);
function listObjs() {
var prefix = 'facebook-' + fbUserId;
bucket.listObjects({
Prefix: prefix
}, function (err, data) {
if (err) {
results.innerHTML = 'ERROR: ' + err;
} else {
var objKeys = "";
data.Contents.forEach(function (obj) {
objKeys += obj.Key + "<br>";
});
results.innerHTML = objKeys;
}
});
}
/*!
* Login to your application using Facebook.
* Uses the Facebook SDK for JavaScript available here:
* https://developers.facebook.com/docs/javascript/gettingstarted/
*/
window.fbAsyncInit = function () {
FB.init({
appId: appId
});
FB.login(function (response) {
bucket.config.credentials = new AWS.WebIdentityCredentials({
ProviderId: 'graph.facebook.com',
RoleArn: roleArn,
WebIdentityToken: response.authResponse.accessToken
});
fbUserId = response.authResponse.userID;
button.style.display = 'block';
});
};
// Load the Facebook SDK asynchronously
(function (d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {
return;
}
js = d.createElement(s);
js.id = id;
js.src = "//connect.facebook.net/en_US/all.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
</body>
</html>
相關推薦
JavaScript in the Browser
<!DOCTYPE html> <html> <head> <title>AWS SDK for JavaScript - Sample Application</title> <script src="h
What happens when you type an URL in the browser and press enter?
address url log pre gpo hand ted ane into What happens when you type an URL in the browser and press enter? 1. You type maps.google.com
Embedding Flash Fullscreen in the Browser Window
For Developers > Design Documents > Embedding Flash Fullscreen in the Browser Window Author: Yu
Could Python’s Popularity Outperform JavaScript in the Next Five Years?
Could Python’s Popularity Outperform JavaScript in the Next Five Years?JavaScript and Python are two influential programming languages for building a wide
Musical Deep Neural Networks in the Browser by Tero Parviainen
This development has many exciting prospects. One of them is that all the work AI researchers have put into musical applications of neural nets is suddenly
How are the image cached in the browser?
Today I encounter a bug.The chrome browser has cached all the images .By chrome dev-tool can find that the images were loaded from
[Javascript] Identify the most important words in a document using tf-idf in Natural
req blog reac lis log require div add frequency Tf-idf, or term frequency-inverse document frequency, is a statistic that indicates how i
怎樣通過程式碼開啟或者關閉瀏覽器控制檯?-How do I close the browser console with code in the console
see:https://stackoverflow.com/questions/25515697/how-do-i-close-the-browser-console-with-code-in-the-console?r=SearchResults 據我所知,沒有一個瀏覽器允許通過程式碼
Creating a Product Recommendation Neural Network in the Web Browser
Creating a Product Recommendation Neural Network in the Web BrowserNeural networks have demonstrated their power over the last few years, creating major br
The Cost Of JavaScript In 2018
We’ve recently added support for flagging high “JavaScript boot-up time” to Lighthouse. This audit highlights scripts which might be spending a long time p
Explain in detail the steps/processes that occur from the moment you type a URL in a browser and hit enter
this (processing typed-in address, adding page to browser history, displaying progress to user, notifying plugins and extensions, rendering the pag
Package gtk+-3.0 was not found in the pkg-config search path
path 二進制 all 項目 有時 rpm fedora ack share 問題描述: 在fedora21系統上通過rpmbuild構建fcitx的二進制包時出現以上錯誤,經老程序員指點:“是相應的開發包沒有安裝” 解決辦法: yum installl gtk3
HiHo1505:小Hi和小Ho的禮物(Meet-In-The-Middle + 組合數學)
整數 image namespace 多少 max using for 2種 100% 時間限制:10000ms 單點時限:1000ms 內存限制:256MB 描述 某人有N袋金幣,其中第i袋內金幣的數量是Ai。現在他決定選出2袋金幣送給小Hi,再選2袋金幣送給小H
TIME IN THE SUBWAY :GUESS NUM !
while switch guess number import java.util.Random;import java.util.Scanner;public class GuessNumber { public static void main(String[] args) {
ORA-23421: job number 225 is not a job in the job queue
conn uil bms delet ext roc erro declare dba_jobs 在對數據庫進行異機恢復之後,為了防止上面作業自動執行,擾亂正常業務系統,需要將測試庫上的作業和db_link進行刪除:但是使用sys用戶連接進去,刪除的時候報如下錯誤SQL
Namespace declaration statement has to be the very first statement in the script
ont 文件 space pac .net button php 解決 img php 中 Namespace declaration statement has to be the very first statement in the script 錯誤解決方
pycharm Zooming in the Editor
can span dialog eas open for .html rotate led https://www.jetbrains.com/help/pycharm/zooming-in-the-editor.html To enable changing font
Maven出現錯誤No plugin found for prefix 'jetty' in the current
jetty jpress Maven出現錯誤No plugin found for prefix ‘jetty‘ in the current project and in the plugin groups的問題解決只需在maven的setting.xml文件上加入如下節點:<pluginGr
解決Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 問題
== number keyword 解決辦法 class rac ref request 反斜杠 通過這裏的回答,我們可以知道: Tomcat在 7.0.73, 8.0.39, 8.5.7 版本後,添加了對於http頭的驗證。 具體來說,就是添加了些規則去限制HTTP頭
unity(使用了NGUI) 在Build時遇見DontSave but is included in the build
clu fonts 自動生成 tsa included image sources ext lag 錯誤提示: An asset is marked with HideFlags.DontSave but is included in the build:Asset: ‘L