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