1
有沒有人有成功將文件從Parse S3 Bucket遷移到自己的S3 Bucket?我有一個包含許多文件(圖片)的應用程序,我使用S3文件適配器從我自己的S3 Bucket和Parse Bucket提供服務,但希望將物理文件遷移到AWS上我自己的Bucket中,現在被託管。解析文件遷移到AWS
在此先感謝!
有沒有人有成功將文件從Parse S3 Bucket遷移到自己的S3 Bucket?我有一個包含許多文件(圖片)的應用程序,我使用S3文件適配器從我自己的S3 Bucket和Parse Bucket提供服務,但希望將物理文件遷移到AWS上我自己的Bucket中,現在被託管。解析文件遷移到AWS
在此先感謝!
如果您已將新Parse實例配置爲使用S3文件適配器託管文件,則可以編寫一個PHP腳本,用於從Parse S3 Bucket下載文件並將其上傳到您自己的文件。在我的例子中(使用Parse-PHP-SDK):
ParseFile
(如果你的服務器配置爲S3,它將被上傳到你自己的S3存儲桶中)。ParseFile
應用於您的輸入。瞧
<?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!";
?>
會試試看。謝謝! – Ricardo