1

I want to export/transfer files to Google drive using Magento 2. Please help me out.

0

You can implement following code in your Magento 2 custom extension. Note that you need to convert it according to Magento 2 extension structure and coding standard.

https://stackoverflow.com/a/25715084/3501113

0

Which file? When you want to upload file on google drive? Is there any specific case ?

So basically you need to use PHP code only to export to the google drive. You need Magento logic just to get the input for google drive API. (File Export)

If there is any specific case like once customer place the order some file has to upload to google drive then you can use Plugins/Observers.

Or

If any some other case you should first find out the place where you can be added the PHP code in the respective controller/Block/Helper.

https://developers.google.com/drive/api/v3/quickstart/php

Updated:

Assuming you have a CSV file to upload : Reference

$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);

About Google_Service_Drive_DriveFile

  • Yes, when the customer places an order an export file should be transferred to Google drive. For file export, I have the code but I need the code to transfer that's it. Could you pls share the test code for files transfer? – gajjala sandeep Feb 13 at 9:27
  • Check my updated answer. – Akhil Gupta Feb 13 at 9:41
  • hey, where we have to give client id and client secret key etc., – gajjala sandeep Feb 13 at 9:51
  • Have a look at Step 1 here- developers.google.com/drive/api/v3/quickstart/php – Akhil Gupta Feb 13 at 10:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.