I am using dropzone js with chunking to take a large file and break it up, each one of those pieces are getting sent to PHP and all the pieces of that large file have a mime type application/octet-stream (if you put the chunk files together it will be video/mp4) now what I am trying to do is put the file back together in Google Drive and here is my PHP code:
public function addFile($filename, $content, $description = '')
{
$file = new GoogleServiceDriveDriveFile();
$file->setName($filename);
$file->setParents([$_ENV['FOLDER_ID']]);
$file->setDescription($description);
$result = $this->driveService->files->create(
$file,
[
'data' => $content,
'mimeType' => 'application/octet-stream',
'uploadType' => 'resumable'
]
);
return sprintf('https://drive.google.com/file/d/%s/view?usp=sharing', $result->getId());
}
The problem I am having is each chunk is getting uploaded to my Google Drive when I am expecting 1 file put together, is what I am trying to do even possible?
2
Answers
I think you would have to write the chunks to the server’s local disk into one file. You can use
file_put_contents( $filename, $chunk, FILE_APPEND );
then use, the dropzone
complete
event handler to notify the server via async request that the upload is completeTry checking the media uploader from the large-file-upload sample