When I upload multiple files to Alibaba Cloud OSS, do I upload files one by one or upload the entire directory at one go?
Alibaba Cloud OSS provides two methods for uploading files.
//Upload a file through multipart upload
function upload_by_multi_part($obj){
$bucket = 'phpsdk1349849394';
$object = 'Mining.the.Social.Web-'.time().'.pdf'; //English
$filepath = "D:\\Book\\Mining.the.Social.Web.pdf"; //English
$options = array(
ALIOSS::OSS_FILE_UPLOAD => $filepath,
'partSize' => 5242880,
);
$response = $obj->create_mpu_object($bucket, $object,$options);
_format($response);
}
//Upload the entire directory using multipart upload
function upload_by_dir($obj){
$bucket = 'phpsdk1349849394';
$dir = "D:\\alidata\\www\\logs\\aliyun.com\\oss\\";
$recursive = false;
$response = $obj->create_mtu_object_by_dir($bucket,$dir,$recursive) ;
var_dump($response);
}
Two approaches are available:
1. The first approach is uploading individual files a time. When the server received N files, it uploads the files in N times using the first function.
2. The second approach is transferring multiple files from a temporary directory to under a folder file and upload them all together using the second function. But I think it is too troublesome – creating a new folder to save the files to be uploaded, and then deleting the folder after the upload is done.
Which approach is better? If the second one is better, can I just create an exclusive temporary directory for the N files directly at the upload?