2016-07-15 55 views
0

我可以使用解析服務器將圖像文件上傳到S3。 (通過從base64圖像數據創建解析文件並在解析文件上執行save())如何創建並上傳視頻以解析服務器?

如何爲視頻文件做同樣的事情?我正在使用打字稿在Ionic 2應用程序中使用parse-server js庫。下面的代碼適用於圖像。

let file = new Parse.File("thumbnail", { base64: imageData }); 
     file.save().then(() => { 
      // The file has been saved to Parse. 
      console.log("File uploaded...."); 
     }, (error) => { 
      // The file either could not be read, or could not be saved to Parse. 
      console.log("File upload failed."); 
     }); 

在視頻文件的情況下,我有從cordova媒體捕獲回調接收到的文件位置。幫助我上傳視頻文件。

謝謝

+0

你到底是怎麼解決的?我正在嘗試新的Parse.File(「name」,{base64:data}),但它的拋出錯誤在同一行。 – InfinitePrime

回答

1

這是我的解決方案經過幾天的研究。 它適用於iphone。
重要說明是這樣的: data = data.replace(「quicktime」,「mov」);

var options = { limit: 1, duration: 30 }; 
navigator.device.capture.captureVideo(function(files){ 
    // Success! Audio data is here 
    console.log("video file ready"); 
    var vFile = files[0]; 
    console.log(vFile.fullPath); 
    ///private/var/mobile/Containers/Data/Application/7A0069EB-F864-438F-A685-A0DAE97F8B2D/tmp/capture-T0x144510b50.tmp.GfXOow/capturedvideo.MOV 
    self.auctionvideo = vFile.fullPath; //localURL; 
    console.log(self.auctionvideo); 

    var fileReader = new FileReader(); 
    var file; 
    fileReader.onload = function (readerEvt) { 
     var data = fileReader.result; 
     data=data.replace("quicktime","mov"); 
     console.log(data); 
     //data:video/quicktime;base64,AAAAFGZ0 
     console.log(data.length); 
     self.auctionvideo=data; 
     self.videofile = {base64:data}; 
    }; 
    //fileReader.reasAsDataURL(audioFile); //This will result in your problem. 
    file = new window.File(vFile.name, vFile.localURL, 
          vFile.type, vFile.lastModifiedDate, vFile.size); 
    fileReader.readAsDataURL(file); //This will result in the solution. 
    // fileReader.readAsBinaryString(file); //This will result in the solution. 
}, 
function(error){ 

}, 
options); 
相關問題