从网址下载图像解析云代码
Download image from url Parse Cloud Code
我正在尝试使用 Parse Cloud Code 下载 facebook 个人资料照片并保存它,但是,重定向似乎无法正常工作 - 有人可以给我一些指导吗?谢谢!
Parse.Cloud.httpRequest({
url: pictureURL,
followRedirects: true
}).then(function(httpResponse){
var imgFile = new Parse.File(request.user.id+".jpg" , httpResponse.buffer);
//the httpResponse does not resolve correctly
return imgFile.save();
}).then(function(){
request.user.set(constants.kBPUserProfileImageKey, image);
request.user.save();
response.success("updated image");
},function(error) {
response.error("failed to save object");
});
首先,我认为 promise 不支持 Parse.Cloud.httpRequest。
查看接口
这是我的代码
// callback(savedParseFile, error)
download: function (url, filename, callback) {
Parse.Cloud.httpRequest({
url: url,
followRedirects: true,
success:function(httpResponse) {
var parseFile = new Parse.File(filename , {base64: httpResponse.buffer.toString('base64', 0, httpResponse.buffer.length)});
// parseFile.save().then(function() {
// callback(parseFile, null);
// }, function(error) {
// console.error('Downloader fails to save parse file.');
// });
parseFile.save({
success:function() {
callback(parseFile, null);
}, error:function() {
callback(null, 'Downloader fails to save parse file.');
}
});
},
error:function(httpResponse) {
callback(null, 'Downloader fails to download file.');
}
});
}
相关文章:
- 在Widget代码中使用javascript从左向右滑动光标图像
- 在jquery中需要cloudinary图像和视频样本代码
- 在Widget代码中没有jQuery的情况下,用光标图像从左滑动到右
- 显示生成的gif;base64图像使用C#代码隐藏在img中使用JavaScript
- 应用将图表转换为图像的jqplot代码时Chrome挂起
- 单击时的图像代码太长
- 使用现有代码更改基于浏览器宽度的图像url
- 请解释Javascript图像旋转代码
- 如何减少图像映射的此 jquery 切换代码
- 我如何完善这个Javascript代码,使其忽略图像中的链接
- 加载所有图像后执行代码
- 使用JavaScript从网页复制HTML代码或图像链接
- 什么错误I'我在下面的jQuery代码中集成filepicker.io来上传一个图像文件
- JavaScript使用based64编码代码降低图像的大小和质量
- 如何通过js将二进制代码的验证图像从api转换为png
- 我如何完善这个Javascript代码,使其只适用于来自图像的链接(而不是来自文本的链接)
- Fancybox图像点击可以独立工作,但不能与我的其他代码一起工作
- 在html画布代码中插入图像不起作用
- 如何编辑此代码以获取图像而不是标题
- 将代码/图像放入我的表格中