2016-06-26 6 views
1

Parse S3 BucketからS3 Bucketにファイルを移行するのに成功した人は誰ですか?私は多くのファイル(画像)を含むアプリケーションを持っており、S3ファイルアダプタを使用して自分自身のS3バケットとパーズバケットの両方からサービスを提供していますが、実際のファイルをAWS上の自分のバケットに移行したいと考えています今すぐホストされます。AWSへのファイルの解析

ありがとうございます!

答えて

2

S3ファイルアダプタを使用して新しいParseインスタンスをホストするように設定した場合は、Parse S3 Bucketからファイルをダウンロードして自分自身にアップロードするPHPスクリプトを作成できます。私の例では(Parse-PHP-SDKを使って):

  1. 私はすべてのエントリをループします。
  2. 私はそれを新しいParseFileとしてアップロードします(サーバーがS3向けに構成されている場合は、自分のS3バケットにアップロードされます)。
  3. 新しいParseFileを入力してください。
  4. ほら

    <?php 
    
           require 'vendor/autoload.php'; 
           use Parse\ParseObject; 
           use Parse\ParseQuery; 
           use Parse\ParseACL; 
           use Parse\ParsePush; 
           use Parse\ParseUser; 
           use Parse\ParseInstallation; 
           use Parse\ParseException; 
           use Parse\ParseAnalytics; 
           use Parse\ParseFile; 
           use Parse\ParseCloud; 
           use Parse\ParseClient; 
    
           $app_id = "AAA"; 
           $rest_key = "BBB"; 
           $master_key = "CCC"; 
    
           ParseClient::initialize($app_id, $rest_key, $master_key); 
           ParseClient::setServerURL('http://localhost:1338/','parse'); 
    
           $query = new ParseQuery("YourClass"); 
           $query->descending("createdAt"); // just because of my preference 
           $count = $query->count(); 
           for ($i = 0; $i < $count; $i++) { 
             try { 
               $query->skip($i); 
               // get Entry 
               $entryWithFile = $query->first(); 
               // get file 
               $parseFile = $entryWithFile->get("file"); 
               // filename 
               $fileName = $parseFile->getName(); 
               echo "\nFilename #".$i.": ". $fileName; 
               echo "\nObjectId: ".$entryWithFile->getObjectId(); 
               // if the file is hosted in Parse, do the job, otherwise continue with the next one 
               if (strpos($fileName, "tfss-") === false) { 
                 echo "\nThis is already an internal file, skipping..."; 
                 continue; 
               } 
    
               $newFileName = str_replace("tfss-", "", $fileName); 
               $binaryFile = file_get_contents($parseFile->getURL()); 
               // null by default, you don't need to specify if you don't want to. 
               $fileType = "binary/octet-stream"; 
               $newFile = ParseFile::createFromData($binaryFile, $newFileName, $fileType); 
    
               $entryWithFile->set("file", $newFile); 
               $entryWithFile->save(true); 
    
               echo "\nFile saved\n"; 
             } catch (Exception $e) { 
               // The conection with mongo or the server could be off for some second, let's retry it ;) 
               $i = $i - 1; 
               sleep(10); 
               continue; 
             } 
           } 
    
           echo "\n"; 
           echo "¡FIN!"; 
    
        ?> 
    
+0

はそれを試してみるだろう。ありがとう! – Ricardo