根据filestack文档,应该在pick
之前调用store
方法。
将文件直接保存到S3存储桶(或其他存储)中。这适用于来自filepicker.pick调用的Blob或来自<input type="file"/>
的DOM File对象
尽管文档中指出了这一点,但是您可以调用store()而不使用pick()
看起来pick
函数向用户显示了界面,我不需要。我只想上传他们在.blob中作为变量编辑过的画布图像,这可能吗?
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));
}
);
}
仅在定义URL而不是Blob的情况下,调用
postFile
才似乎有效。如果有斑点,它会抛出:Cannot store given input: " + input + ". Not a string, file input, DOM File, or FPFile object.
最佳答案
因此,您似乎正在尝试将filepicker.store()方法传递给画布数据URL。 API无法处理此问题。
它将使用原始的base64字符串(还需要传递base64decode参数),标准文件输入a DOM File或来自先前Filestack事务(fpFile对象)的响应。
canvas数据网址可能是这样的:
“ data:image / gif; base64,R0lGODlhAQABAIAAAAAAAP //// ywAAAAAAQABAAACAUwAOw ==”
Filestack API的期望是:
“ R0lGODlhAQABAIAAAAAAAP /// ywAAAAAAQABAAACAUwAOw ==”
这是一个使用store保存base64字符串的示例。
https://jsfiddle.net/amione/tq2zqtg1/
var data = "iVBORw0KGgoAAAANSUhEUgAAAIgAAAA1CAYAAACa7qP5AAAKGklEQVR4Xu2cBcx2NxXHf0OCuxMIMCS4Oxu6DQ0QNPhCkAAjWJBgYwsOwzZ0+HAILhsuw12GB3d3CTDI70tLSr+2t/c+z/uQJ2+bfMmX57anvaf/nvM/5/S++zDa0EBDA/sM7QwNtDQwADLw0dTAAMgAyADIwMByDQwLslx3u2LkAMiu2OblLzkAslx3u2LkAMiu2OblLzkAslx3u2LkAMiu2OblLzkAslx3u2LkAMiu2OblL5kC5PTAuYF/JuJOBvwI+NPyKcbImRo4KXDaMEb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");
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>
关于javascript - 是否可以不使用pick方法存储文件?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43003905/