According to the filestack documentation you are supposed to call the pick
method prior to store
Save files directly to your S3 bucket (or other storage). This works for both Blobs from a filepicker.pick call or for DOM File objects from an
<input type="file"/>
Though the document states this, you can call store() without pick()
It looks like the pick
function shows the interface to the user, which I do not want. I just want to upload a canvas image they've edited as a variable in my .blob, is this possible?
var canvasImage = canvas.toDataURL("image/png");
var blob = {
mainFile: canvasImage,
filename: this.file.name + '_edited',
isWriteable: true,
};
postFile(blob) {
var _this = this;
this.filepickerService.store(blob,
{
mimetype: "text/plain",
location: "S3",
path: "muhPath"
container: _this.appConfig.s3Bucket
},
function(new_blob){
console.log(JSON.stringify(new_blob));
}
);
}
Calling postFile
only appears to work if I define a url instead of a blob. With a blob it throws:
Cannot store given input: " + input + ". Not a string, file input, DOM File, or FPFile object.
So, it looks like you are trying to pass the filepicker.store() method a canvas data url. This is not something the API can process.
It will take a raw base64 string (that you would also need to pass the base64decode parameter with), a standard file input, a DOM File , or the response from a previous Filestack transaction (fpFile object).
The canvas data url is probably something like this: "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw=="
What the Filestack API expects would be: "R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw=="
Here is an example that uses store to save a base64 string. https://jsfiddle.net/amione/tq2zqtg1/
var data = "iVBORw0KGgoAAAANSUhEUgAAAIgAAAA1CAYAAACa7qP5AAAKGklEQVR4Xu2cBcx2NxXHf0OCuxMIMCS4Oxu6DQ0QNPhCkAAjWJBgYwsOwzZ0+HAILhsuw12GB3d3CTDI70tLSr+2t/c+z/uQJ2+bfMmX57anvaf/nvM/5/S++zDa0EBDA/sM7QwNtDQwADLw0dTAAMgAyADIwMByDQwLslx3u2LkAMiu2OblLzkAslx3u2LkAMiu2OblLzkAslx3u2LkAMiu2OblLzkAslx3u2LkAMiu2OblL5kC5PTAuYF/JuJOBvwI+NPyKcbImRo4KXDaMEb9/w3480wZa+ueAuQOwCsKkq8OfHxtMw5BNQ1cBrgbcEihw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lnkf3ZnIwbR4AM59+wqDOzOSauEpb64ZYrUyRjjHE9Z1qF5HSueRrteY1SMsSXms4psfFREF5CCbTNWtYy1mkmb4aQGrZQC2WpKzUUoC0cjDe/i4xdWX2hHk1pu/4UjhqmGkOomSdTOMbbkbuUsv+WnaQo6TfIZmtlpuVIj95iWn1nktKqS57rXNXFJMKNoHjyTpDMMctv67p/2oYLFk1vC01rZOK9SV1A55g733U2h52HR6WStrpOOtHnujvhR89GeZ1/L3ULI2/PDzQOplQq5HdWAjUSnnNwPpMrW+6ZsXX3IzPtAr3DHNbTVbntTZFbGvjeg7InrFzLEhjnXs9cgN9yYjsdYaNeV2oN5M6tX43RoWnJrplRabkxed5ETD+PvUJwpT86A7nfvqg3LUDREvQm9yy7uCJSr8A6wlzpxQSn5vQ0iJFxfTe2J6Sn1ZcY19lm+Mp1YSm5EVr4L2OaMHSMRJrK7w5F+mVm4O5Z1zss1aAaHYldT0A8RQannolIG+6jy905icEmfceLLSVbonl5FYu8sxwA3yOomLfqdBZHehS5jTfwfuxJXBEOfIW75zUvnQrzaeOjcZWyfQu4iA1nmBdwkVp2kvfjcaXkHBagW3dRNevT8mxhK0cI5HatxyGx35LnJtX784Kqp6ch+s2vf3UxoWjdIMEuF+zle6Y5BspcdTNxvsiLWBJ9nU3z+9An6RU/a3yFYHTlIp6/r7Xx1hz//yD5EryKbOWkcsxvP5nyXnOXwCwauttdkmdLyt51I1pYVb9ONkXjUmyC4c5NOdeIXAz5BhfXmEuQa5VMyrx/15VMHz1kwcLfHKOJYk016dcrYllCZuXl/ycwiyzhLl0z7cDV8u7zAXI8pnGyK3UwADIVm7b5hY9ALI5XW/lTAMgW7ltm1v0AMjmdL2VMw2AbOW2bW7RAyCb0/VWzjQAspXbtrlFD4BsTtdbOdN/AFXvVFQqjXs4AAAAAElFTkSuQmCC";
Here is an example
filepicker.setKey("AtpK5JtiRgm3nWbe1vlI1z");
filepicker.store(
data, {
base64decode: true,
filename: 'image.png'
},
function(Blob) {
console.log("Store successful:", JSON.stringify(Blob));
addLink(Blob);
},
function(FPError) {
console.log(FPError.toString());
},
function(progress) {
console.log("Loading: " + progress + "%");
}
);
function addLink(data) {
$("#results")
.append(
'<li><a target="_blank" href="' +
data.url + '">' + data.filename + '</a></li>'
);
}
<script src="https://api.filestackapi.com/filestack.js"></script>
<ul id="results">
</ul>