Level 80
@mash square You’re re-inventing the wheel and building something Laravel Vapor has already taken care of for you: https://docs.vapor.build/1.0/resources/storage.html#file-uploads
Hi all!
How can I set correctly fopen? Since I don't know the initial file position I get a 500 error when trying to upload.
$s3Client = new S3Client([
'profile' => 'default',
'region' => 'us-east-2',
'version' => '2006-03-01'
]);
$bucket = 'your-bucket';
$key = 'my-file.zip';
// Using stream instead of file path
$source = fopen('/path/to/large/file.zip', 'rb');
$uploader = new ObjectUploader(
$s3Client,
$bucket,
$key,
$source
);
do {
try {
$result = $uploader->upload();
if ($result["@metadata"]["statusCode"] == '200') {
print('<p>File successfully uploaded to ' . $result["ObjectURL"] . '.</p>');
}
print($result);
} catch (MultipartUploadException $e) {
rewind($source);
$uploader = new MultipartUploader($s3Client, $source, [
'state' => $e->getState(),
]);
}
} while (!isset($result));
fclose($source);
@mash square You’re re-inventing the wheel and building something Laravel Vapor has already taken care of for you: https://docs.vapor.build/1.0/resources/storage.html#file-uploads
Please or to participate in this conversation.