我正在尝试使用<input type='file'>
和Contentful management api从浏览器中选择文件。
我已经使用网上已有的文件对其进行了测试,例如此处的示例: Angular & Contentful: Cannot create asset inside a space 而且效果很好,当我选择一个文件并尝试从生成的Blob中使用它时,问题就来了。这就是我要做的:
fileChangedHandler = (e) => {
const file = e.target.files[0];
if (file) {
this.setState({
file: {
selectedFile: file,
fileUrl: URL.createObjectURL(file),
},
});
}
};
然后我在此处使用fileUrl
作为上传资源:
environment.createAsset({
fields: {
title: {
[locale]: selectedFile.name,
},
file: {
[locale]: {
contentType: selectedFile.type,
fileName: selectedFile.name,
upload: fileUrl,
},
},
},
})
但是我收到一个错误消息,说该值与正则表达式验证不匹配,因为它以'blob'开头,而不是正确的url
我也尝试在selectedFile
属性中使用upload
,但再次引发另一个错误:
有什么想法吗? 谢谢!
答案 0 :(得分:0)
对我来说很难解决此问题,但是您可以看一下此示例。
https://github.com/contentful-labs/file-upload-example:)
它使用Content Management API上传文件。