flysystem-google-drive
flysystem-google-drive copied to clipboard
Set mimetype on upload is case sensitive
Google Drive allows you to convert a file while you upload. For example upload a PPT to a Google Presentation or upload a csv and get a Google Sheet.
Apparently all that is needed for that is to set the mime type, which can be easily done, if you know how, by passing an extra parameter to the write function of filesystem.
$adapter = new GoogleDriveAdapter(
$this->service,
getenv('GOOGLE_DRIVE_FOLDER_ID')
);
$this->filesystem = new Filesystem($adapter);
// convert PPT to presentation by setting the mimetype
$stream = fopen($this->files[$this->file_id]['tmp_name'], 'r+');
$response = $this->filesystem->putStream(
$this->getNewFilename(),
$stream,
[
'mimetype' => 'application/vnd.google-apps.presentation',
]
);
The inconsistency is that the Google API illustrates the use of mimeType
vs mimetype
as used by the GoogleDriveAdapter.
// https://developers.google.com/drive/api/v3/manage-uploads#multipart
$fileMetadata = new Google_Service_Drive_DriveFile(array(
'name' => 'My Report',
'mimeType' => 'application/vnd.google-apps.spreadsheet'));
$content = file_get_contents('files/report.csv');
$file = $driveService->files->create($fileMetadata, array(
'data' => $content,
'mimeType' => 'text/csv',
'uploadType' => 'multipart',
'fields' => 'id'));
printf("File ID: %s\n", $file->id);
https://github.com/nao-pon/flysystem-google-drive/blob/9c89e0e4a3f350e3f422e80d2ef24ac9aeb76d65/src/GoogleDriveAdapter.php#L1064
Someone might find this information useful. There is no need for a fix as such, just for others to be aware and use mimetype
when passing it to the method vs Google's mimeType
.
Resources: https://developers.google.com/drive/api/v3/manage-uploads#multipart https://developers.google.com/drive/api/v3/mime-types https://developers.google.com/drive/api/v3/integrate-open#open_and_convert_google_docs_in_your_app