解析云 - 从URL获取缩略图

时间:2016-07-27 12:56:40

标签: javascript android parse-platform cloud-code

在我的ParseCloud-function中,我想从网址中检索缩略图(JPG / PNG)并将其另存为ParseFile

ParseCloud功能

Parse.Cloud.define("statusDone",function(request,response)
{
Parse.Cloud.useMasterKey();

var doneObjectId = request.params.doneObject;

s_status      = request.params.s_status;
s_message     = request.params.s_message;
s_link        = request.params.s_link;

var StatusObject = Parse.Object.extend("Status");
var sObject = StatusObject .createWithoutData( doneObjectId );
sObject .set("isDone", true);
sObject .set("link", s_link);
sObject .set("message", s_message);
sObject .set("statusColor", s_statusColor);

...

} 

在此,我想获取link的缩略图并将其另存为ParseFile

1 个答案:

答案 0 :(得分:0)

你可以做的是在你的云代码中使用Parse.Cloud.httpRequest,从那里执行对s_link的调用,得到结果并将其保存在Parse.File这里是一些代码片段:

 Parse.Cloud.httpRequest({
      url: s_link,
      headers: {
          // in case you need request headers
      }
  }).then(function(res) {
    // here you get the result from here you can create your Parse.File in the following way (from parse js DOCS).
    // 1. create file with bytes
    // var bytes = [ 0xBE, 0xEF, 0xCA, 0xFE ];
    // var file = new Parse.File("file_name}", bytes,"{content_type}");
    // 2. create with base64 string 
    // var base64 = "V29ya2luZyBhdCBQYXJzZSBpcyBncmVhdCE=";
    // var file = new Parse.File("myfile.txt", { base64: base64 });
  });