Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding support for fetching the file being saved from the web if it i…

…s a URL
  • Loading branch information...
commit 0d4a814804e4c7b99172d7e39e96d22480bb4a69 1 parent b8a3442
Paul Kinlan authored
View
2  server/demos/cloudfilepicker/pages/index.html
@@ -65,7 +65,7 @@
function returnImage (e) {
if(!!window.intent) {
// Load the image via a proxy
- loadImage(e, function(data) {
+ loadFile(e, function(data) {
window.intent.postResult(data);
setTimeout(function() { window.close();}, 500);
});
View
10 server/demos/cloudfilepicker/static/scripts/proxy.js
@@ -2,7 +2,7 @@
var BlobBuilder = window.BlobBuilder || window.MozBlobBuilder || window.WebKitBlobBuilder;
-function loadImage(url, callback) {
+function loadFile(url, callback, asBlob) {
var xhr = new XMLHttpRequest();
xhr.onload = function() {
// convert array buffer to blob.
@@ -15,7 +15,13 @@ function loadImage(url, callback) {
callback(data);
};
var contentType = xhr.getResponseHeader("Content-type");
- fileReader.readAsDataURL(bb.getBlob(contentType));
+ var blob = bb.getBlob(contentType);
+ if(asBlob) {
+ callback(blob);
+ }
+ else {
+ fileReader.readAsDataURL(blob);
+ }
};
xhr.responseType = 'arraybuffer';
xhr.open("GET", "proxy?url=" + encodeURIComponent(url));
View
22 server/demos/cloudfilepicker/static/scripts/save.js
@@ -42,13 +42,21 @@
insertFileData(data, authResult, processResponse);
}
else if(typeof(data) == "string" ) {
- var saveImg = document.getElementById("save-img");
- saveImg.src = window.webkitIntent.data;
- var meta = {
- 'title': "Test Image " + (new Date()).toJSON(),
- 'mimeType': window.webkitIntent.type
- };
+ if(data.indexOf("http") == 0) {
+ // Data is at a URL so fetch it.
+ loadFile(data, function(fileData) {
+ insertFileData(fileData, authResult, processResponse);
+ }, true);
+ }
+ else {
+ var saveImg = document.getElementById("save-img");
+ saveImg.src = window.webkitIntent.data;
+ var meta = {
+ 'title': "Test Image " + (new Date()).toJSON(),
+ 'mimeType': window.webkitIntent.type
+ };
insertBase64Data(data.replace(/data:image\/([^;]*);base64,/,""), window.webkitIntent.type, meta, authResult, processResponse);
+ }
}
}
});
@@ -95,7 +103,7 @@
// TODO: how to set the correct values to these fields?
var contentType = fileData.type || 'application/octet-stream';
var metadata = {
- 'title': fileData.fileName,
+ 'title': fileData.fileName || "Test Image " + (new Date()).toJSON(),
'mimeType': contentType
};
Please sign in to comment.
Something went wrong with that request. Please try again.