【发布时间】:2018-10-17 00:43:23
【问题描述】:
谁能指导我如何通过 angularjs 或 javascript 在内容媒体库中上传图片?
我浏览了内容丰富的文档,但找不到任何东西。
我找到了这个 sn-p,但我不这么认为它会上传到媒体库中:
var request = new XMLHttpRequest();
request.open('POST', 'https://api.contentful.com/spaces/5smsq22uwt4m/assets');
request.setRequestHeader('Authorization', 'Bearer b4c0n73n7fu1');
request.setRequestHeader('Content-Type', 'application/vnd.contentful.management.v1+json');
request.onreadystatechange = function () {
if (this.readyState === 4) {
console.log('Status:', this.status);
console.log('Headers:', this.getAllResponseHeaders());
console.log('Body:', this.responseText);
}
};
var body = "{ \
'fields': { \
'title': { \
'en-US': 'Bacon Pancakes' \
}, \
'file': { \
'en-US': { \
'contentType': 'image/jpeg', \
'fileName': 'example.jpeg', \
'upload': 'https://example.com/example.jpg' \
} \
} \
} \
}";
request.send(body);
感谢您的帮助。
【问题讨论】:
标签: javascript angularjs image-uploading contentful