2017-06-14 83 views
0

我使用express +解析服务器,我想在服务器端设计一个node.js函数来复制图像。我可以查询并获取现有的分析文件,但是如何复制并保存新分析文件?如何复制Parse.File(图片)

var imageQuery = new Parse.Query("ProductImage"); 
    imageQuery.equalTo("products", product); 
    imageQuery.find({ 
     success: function(productImages) { 

      if (productImages.length > 0) { 
       var image = productImages[0].get("imgoneS"); 
       for (var key in image) { 
        console.log(key + ": " + image[key]); 
       } 
       //console.log key only _url and _name 
       //how to copy a new image and save? 

      } 


     }, 
     error: function(error) { 
      console.error("product_stat_copyproduct ProductImage query error: " + error); 

     } 
    }) 
+0

请显示您的尝试以及您已尝试的代码? – Hexie

+0

我有更新并记下我现有的代码。 –

+0

你想复制网址或网址内的所有数据? –

回答

0

你可能需要做的是从文件中获取数据,并用该数据初始化一个新文件。像这样的东西(未测试)应该在云代码中工作。 Parse.Cloud.httpRequest仅适用于Cloud Code,如果您在客户端JS,使用请求或其他网络库中执行此操作:

Parse.Cloud.httpRequest({ url: originalFile.url()}).then(function(response) { 
    // The file contents are in response.buffer. 
    var copiedFile = new Parse.File("MyCopy.someExtension", response.buffer); 
    return copiedFile.save(); 
}.then(function() { 
    //copied file was saved! 
});